为了账号安全,请及时绑定邮箱和手机立即绑定

Vue2.0 如何动态切换组件?

Vue2.0 如何动态切换组件?

拉风的咖菲猫 2018-10-11 14:35:54
点击按钮切换组件 但切换不了js:var Rm={    template:'#aa', }var Wr={    template:'#bb', }var vm=new Vue({    el:'#app',    data:{        currentView:Rm,        picked:0     },    mounted:function(){     },    watch:{        'picked':function(val){            this.currentView=Wr                 console.log(this.currentView)         }     }, })html<script type="text/x-template" id="rm">     <div>123</div><script><script type="text/x-template" id="wr">     <div>456</div><script><component :is="currentView"></component>报错内容是 vue2.0.js:2611 [Vue warn]: Cannot find element: #wrvue2.0.js:2611 [Vue warn]: You are using the runtime-only build of Vue where the template option is not available. Either pre-compile the templates into render functions, or use the compiler-included build. (found in anonymous component - use the "name" option for better debugging messages.)
查看完整描述

1 回答

  • 1 回答
  • 0 关注
  • 1557 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信