vue2.0路由寫法

// 0. 若是使用模塊化機制編程,導入Vue和VueRouter,要調用 Vue.use(VueRouter)

			// 1. 定義(路由)組件。
			// 能夠從其餘文件 import 進來
			var  Foo = {
				template: '<div>foo</div>'
			}
			var  Bar = {
				template: '<div>bar</div>'
			}
          var x = require("A");
			// 2. 定義路由
			// 每一個路由應該映射一個組件。 其中"component" 能夠是
			// 經過 Vue.extend() 建立的組件構造器,
			// 或者,只是一個組件配置對象。
			// 咱們晚點再討論嵌套路由。
			var routes = [{
					path: '/foo',
					component: Foo
				},
				{
					path: '/bar',
					component: Bar
				}
			]

			// 3. 建立 router 實例,而後傳 `routes` 配置
			// 你還能夠傳別的配置參數, 不過先這麼簡單着吧。
		    var  router = new VueRouter({
				routes // (縮寫)至關於 routes: routes
			})
			var app = new Vue({

				el: "#app",
				router
			})
相關文章
相關標籤/搜索