Vue 内置组件component

1

路由跳转<router-link>(或this.$router.push)与<router-view>在同一个vue里
vue是单页面应用,所有页面都在app.vue里
在app.vue里有<router-link><router-view>可以接受home组件
在home.vue里又有<router-link><router-view>

虽然叫路由跳转,在地址栏url也变化了,但其实没有跳到其他页面.
路由跳转是沿用以前多页面的叫法,在单页面应用中,其实是将其他页面加载到当前页面中,或者叫路由引用更为合适.

2 内置component

使用:is属性,动态渲染组件。
<component :is='state'></component>

示例:
<div id="app">
  <button @click="change1">son1</button>
  <button @click="change2">son2</button>
  <component :is='state'></component>
</div>
 
<script>
 var vm = new Vue({
    el: "#app",
    data() {
        return {
            state: 'son1'
        }
    },
    methods: {
        change1() {
            this.state = 'son1'
        },
        change2() {
            this.state = 'son2'
        }
    },
    components: {
        son1,
        son2
    }
 })
</script>
posted @   波吉国王  阅读(300)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 分享4款.NET开源、免费、实用的商城系统
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
· 上周热点回顾(2.24-3.2)
点击右上角即可分享
微信分享提示