1. 查找最新版本的 在package.json? "vue-router": "^2.2.1" ? ?
cnpm install
2.在入口文件main.js寫入
import VueRouter from 'vue-router';
Vue.use(VueRouter)
import goods from './components/goods/goods'
import ratings from './components/goods/ratings'
import seller from './components/goods/seller'
import good1 from './components/goods/goodsg/good1'
import good2 from './components/goods/goodsg/good2'
import good3 from './components/goods/goodsg/good3'
const routes = [
{ path: '/', component: goods },
{ path: '/goods', component: goods,children:[
{path:'/',component:good1},
{path:'/good1',component: good1},
{path:'/good2',component: good2},
{path:'/good3',component: good3},
]
},
{ path: '/ratings', component: ratings },
{ path: '/seller', component: seller },
]
const router = new VueRouter({
routes
})
const app = new Vue({
router,
render: h =>h(App)
}).$mount('#app')
3. html 文件中寫入
/goods ?是main.js 里面 import 進(jìn)來的 /goods?
通過路由傳參數(shù) ?直接可以 在 模板里面 舉個栗子 ?:
{path: '/goods',name:"fisrt", component: goods} ?直接加一個name屬性即可?
?調(diào)用 $route.name 就能輸出
to="/goods" ?轉(zhuǎn)換成json格式 ?to="{name='aa',Id=123}" ??
調(diào)用$route.name ? $route.id ?