zoukankan      html  css  js  c++  java
  • Vue路由

    组件

    全局组件
        import Index from './components/index.vue';
        
     Vue.component("Index", Index);
     
    局部组件
    
    在template标签中
    
    <Index/>
    
    在app.vue中的script标签中
    
    import Index from './components/index.vue';
        
    export default {
      name: 'App',
      components:{
        Index
      }
    }

    router路由

    1. 
        // 下载
        cnpm install --save-dev vue-router
    
    2.
    
        // 引入
        import VueRouter from "vue-router"
        
        // 创建一个主路由并引入
        import Index from '../components/index.vue';
    
    3. 
        // 挂载路由
        Vue.use(VueRouter);
    
    4. 
        // 实例化
        
    let router = new VueRouter({
        routes: [{
            path: '/index',
            component: Index
            }]
        })
    
    5. 在实例化vue中添加router
    
    new Vue({
        el: '#app',
    // 添加router:router 可省略
        router,
        components: { App },
        template: '<App/>'
    })
    
    6.在app.vue的template中
    
        <router-view></router-view>

    组件的概念

    1.组件是vue最强大的功能
    
    2.可以扩展html元素,封装可重用的代码
    
    3.组件系统让我们可复用的小组件来构建大型应用
  • 相关阅读:
    构建之法阅读笔记02
    4.7-4.13 第八周总结
    构建之法阅读笔记01
    顶会热词统计
    结对作业-四则运算升级版
    3.31-4.5 第七周总结
    大道至简阅读笔记03
    3.23-3.30 第六周总结
    第7周总结
    人月神话阅读笔记之三
  • 原文地址:https://www.cnblogs.com/2oex/p/9569210.html
Copyright © 2011-2022 走看看