Vue-cli3项目案例

新建项目的过程不多说了,参考:https://blog.csdn.net/qq_40323256/article/details/100999860 

例1:极简的一个例子

  运行结果:    Vue-cli3项目案例_第1张图片                      结构目录: Vue-cli3项目案例_第2张图片

A.vue


B.vue


Home.vue


router.js

import Vue from 'vue'
import Router from 'vue-router'

import Home from './views/Home.vue'
import A from './views/A.vue'
import B from './views/B.vue'

Vue.use(Router)

export default new Router({
  routes: [
    {
      path: '/',
      component: Home
    },
    {
      path: '/a',
      component: A 
    },
    {
      path: '/b',
      component: B  
    }
  ]
})

App.vue

main.js

import Vue from 'vue'

import App from './App.vue'
import router from './router'

Vue.config.productionTip = false

new Vue({
  router,
  render: h => h(App)
}).$mount('#app')

例2:对比例1

运行结果:Vue-cli3项目案例_第3张图片      结构目录(和例1一样): Vue-cli3项目案例_第4张图片

其他代码和例1相同,不同的是Home.vue和router.js,注意体会代码的不同之处

Home.vue


router.js

import Vue from 'vue'
import Router from 'vue-router'

import Home from './views/Home.vue'
import A from './views/A.vue'
import B from './views/B.vue'

Vue.use(Router)

export default new Router({
	routes: [{
		path: '/',
		component: Home,
		children: [{
				path: '/a',
				component: A
			},
			{
				path: '/b',
				component: B
			}
		]
	}]
})

 

你可能感兴趣的:(Vue)