javascript - webpack中使用vue路由设置不报错,但是不能显示啊啊
高洛峰
高洛峰 2017-04-17 16:38:31
0
2
1057

设置好了vue路由,npm run dev一下,不报错,但是路由不生效啊
代码如下:

//引入路由模块
import VueRouter from 'vue-router'
//使用路由模块
Vue.use(VueRouter);
//加载组件
import home from './components/Home/home.vue';

//创建路由对象
const router = new VueRouter({
    //配置router-link 指向的路由发生变化时候,当前a标签增加的激活样式
    routes: [
        {name: 'Home', path: '/home', component: home},
    ]
})


var vm = new Vue({
    el: '#app',
    render: h => h(app),    //h 是 createElement这个函数  编译app.vue组件
    //使用路由对象
    router: router
});`请输入代码`
还有:
    <template>
    <p class="mui-content">
        home
    </p>
</template>

<script>
    export default {
        data () {
            return{

            }
        }
    }
</script>

<style scoped>

</style>
图片:
![图片描述][1]
高洛峰
高洛峰

拥有18年软件开发和IT教学经验。曾任多家上市公司技术总监、架构师、项目经理、高级软件工程师等职务。 网络人气名人讲师,...

reply all(2)
Ty80

It seems like this

vue-router

Ty80

You didn’t post the code in App.vue. I don’t know if you wrote it

Vue.use(Router)
Vue.use(Vuex)
export default new Router({
  routes: [
    {
      path: '/',
      component: App,
      redirect:'/in_theaters'},
    {
      path: '/in_theaters',
      component: in_theaters,
    },{
      path: '/coming_soon',
      component: coming_soon,
    },
    {
      path: '/top250',
      component: top250,
    },
    {
    path:'*',
      redirect:'/'
    }
  ]
})

After configuring the routing,
refer to the routing path in App.vue. This content probably means that this is where your Home.vue is loaded

  <el-col   :md="14" :lg="18" class="content">
        <router-view></router-view>
      </el-col>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template