Vue从零到实战项目-来源三人行慕课

原文链接:http://www.3mooc.com/front/articleinfo/97

项目概要

本项目用到的技术栈: vue-cli + vue-router + vuex + axios

如何在本地运行本项目

git clone https://gitee.com/ehcto/vuecli3_rangers.git

cd vuecli3_rangers

npm i 或 cnpm i

npm run serve

项目文档说明

├── node_modules/ #模块文件

├── src/ #项目入口目录

    ├── assets/   #前端资源目录

    ├── components/   # vue组件目录/.vue文件存放目录

    ├── router/  # vue路由管理目录 

    ├── store/ # vuex状态管理目录

    ├── App.vue # 项目根组件

    ├── main.js # 项目入口文件

├── test/ #测试目录

├── package.json #包文件信息

├── .babelrc

├── README.md

功能简单介绍

main.js

import Vue from 'vue'

import App from './App.vue'

import router from './router'

import store from './store'

//reset.css ==>重置样式

import './assets/css/reset.css'

//fastClick ==>解决click事件在移动端300ms延迟的问题

import FastClick from 'fastclick'

FastClick.attach(document.body);

//引入字体图标

import './assets/css/iconfont.css'

//引入适配font.js文件

import './assets/js/font.js'

//引入swiper

import VueAwesomeSwiper from 'vue-awesome-swiper'

Vue.use(VueAwesomeSwiper)

import './assets/css/swiper.css'

//引入动画库animate.css

import animate from 'animate.css'

//引入axios

import axios from 'axios'

Vue.prototype.axios = axios

Vue.config.productionTip = false

new Vue({

  router,

  store,

  render: h => h(App)

}).$mount('#app')

路由管理

import Vue from 'vue'

import Router from 'vue-router'

Vue.use(Router)

import Home from './components/home/Home'

export default new Router({

  mode: 'hash',

  base: process.env.BASE_URL,

  routes: [

    {

      path: '/',

      name: 'home',

      component: Home

    },

    {

      path: '/city',

      name: 'city',

      component: () => import('./components/city/City.vue')

    },

    {

      path: '/details',

      name: 'details',

      component: () => import('./components/details/Details.vue')

    }

  ]

})

vuex管理

import Vue from 'vue'

import Vuex from 'vuex'

Vue.use(Vuex)

let defaultCity = '北京';

defaultCity = localStorage.city;

export default new Vuex.Store({

  state: {

  cityName:defaultCity

  },

  mutations: {

  changeCity(state,city){

  state.cityName=city;

      localStorage.city=city

  }

  },

  actions: {

  }

})

App.vue

<template>

  <div>

      <keep-alive>

      <router-view></router-view>

      </keep-alive>

  </div>

</template>

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • vue去哪网跟学笔记 记录学习点滴 1. 初始化项目 1.1 手机显示配适 minimum-scale=1.0,m...
    noobakong阅读 2,409评论 0 16
  • 1、active-class是哪个组件的属性?嵌套路由怎么定义?答:vue-router模块的router-lin...
    jane819阅读 1,819评论 0 15
  • 项目地址https://github.com/hongchh/timeline-x 一、成品展示 二、项目需求 添...
    前端杨肖阅读 9,548评论 0 10
  • 有位和尚,为了显露自己修行的高深,总把“我不入地狱,谁入地狱”这句话挂在嘴边。一天夜里,佛祖向他显现,并带他到地狱...
    海王星1984阅读 274评论 0 0
  • 陷在另一个时间区域 你有没有想到过,活在你现在的年纪,如果你从来没有想到自己会一直活下去,或者如果你从来没有想到你...
    玻璃先生阅读 226评论 0 0

友情链接更多精彩内容