动态组件与v-once指令

📅 2026/7/28 18:49:14
动态组件与v-once指令
点击切换child-one和child-two显示与隐藏!DOCTYPE html html langen head meta charsetUTF-8 title动态组件与v-once指令/title script src../js/vue.js typetext/javascript/script /head body div idapp child-one :contentresult v-ifresult childOne/child-one child-two :contentresult v-ifresult childTwo/child-two button clickchange变化/button /div /body script Vue.component(child-one,{ props:[content], template:div{{content}}/div }) Vue.component(child-two,{ props:[content], template:div{{content}}/div }) var app new Vue({ el:#app, data:{ result:childOne }, methods:{ change:function () { this.result this.result childOne ? childTwo : childOne; } } }) /script /html