Vue study notes (2)

The use of vue2.0 vue router

App.view

<template>
  <div id="app">
    <v-header></v-header>
    <div class="tab">
      <router-link class="tab-item" to="/goods">商品</router-link>
      <router-link class="tab-item" to="/ratings">评论</router-link>
      <router-link class="tab-item" to="/seller">商家</router-link>
    </div>
    <div class="content">
      <router-view></router-view>
    </div>
  </div>
</template>

main.js

import Vue from 'vue';
import VueRouter from 'vue-router';

import App from './App';
import goods from 'components/goods/goods';
import ratings from 'components/ratings/ratings';
import seller from 'components/seller/seller';

Vue.use(VueRouter);

const router = new VueRouter({
  routes: [
    { path: '/goods', component: goods },
    { path: '/ratings', component: ratings },
    { path: '/seller', component: seller }
  ]
});

/* eslint-disable no-new */
// 跳过no-new 的eslint校验
new Vue({
  router,
  el: '#app',
  components: { App },
  template: '<App/>'
}).$mount('#app');

router.push('/goods');

Note that the default routing setting here is push, while vue 1.0 is go. If you use router.go('/goods'); in vue2.0, there will be an infinite loop problem.

In addition, the components path here should be ../components, and here is the configuration of the webpack path,

webpack.base.conf.js

resolve: {
    extensions: ['.js', '.vue', '.json'],
    alias: {
      'vue$': 'vue/dist/vue.esm.js',
      '@': resolve('src'),
      'components': resolve('src/components'),
      'common': resolve('src/common')
    }
  },
The configuration here is also different from vue1.0


I hope my experience of entering the pit is helpful to you, may the Holy Light be with you



Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324350163&siteId=291194637