首页 > 编程知识 正文

vue3.0动态组件,vue表单动态添加组件

时间:2023-05-06 00:12:23 阅读:244021 作者:2451

1.怎么使用动态组件? 1.< component >标签2.:is属性3.动态组件能自动切换组件,进行内容渲染 <!DOCTYPE html><html><head><meta charset="utf-8"><title>vue动态组件</title><script src="./vue.js"></script></head><body><div id="app"><component :is="type"></component><button @click="headleBtnClick">change</button></div><script>Vue.component('child-one',{template: '<div v-once>child-one</div>'})Vue.component('child-two',{template: '<div v-once>child-two</div>' //动态组件每次回销毁一个组件,再创建另一个组件进行显示。 //v-once指令可以将静态内容加载入内存中, })var vm = new Vue({el: '#app',data: {type: 'child-one'},methods: {headleBtnClick: function(){this.type = (this.type === 'child-one'?'child-two' : 'child-one' )}}})</script></body></html>

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。