在使用Vue路由的时候遇到的一个错误:

使用官方的路由插件:Vue-router

1.导入插件

        <script src="https://unpkg.com/[email protected]/dist/vue-router.js"> 
        </script>

2.设置路由对象

 var routes=[{
                        path:'/about',
                        component:{
                            template:'<div>这是第一个组件</div>'
                        }          
                   }
                            ,
                    {   path:'/',
                         component:{
                                template: '<div>第二个组件</div>'
                        
                         }
                    }
                 ]                            

3.绑定路由对象到Vue实例上

  
            var vm=new Vue({
                    el:'#demo',
                    data:{
                       
                    },
                    router:router
                    
            
            })

发现了一个错误:

经过排查发现了原因:Vue-router插件依赖于Vue框架,应该先导入框架Vue

猜你喜欢

转载自www.cnblogs.com/onlyx/p/12303837.html