vuejs如何重新实例化某个组件。

<el-button type="primary">主要按钮</el-button>如果直接使用该行代码,则出现蓝色按钮
而<el-button>主要按钮</el-button>的话则是普通按钮

我想着先写<el-button>主要按钮</el-button>后,获取其标签对象,给它增加这个属性:
obj.setAttribute('type', 'primary'),希望通过这一操作来使其变为蓝色按钮。

而目前直接这样操作并不会改变按钮的颜色,想着是否能通过使该组件重新实例化一次来识别这个type属性,其他方法亦可,求大神指点~


千巷猫影
浏览 2740回答 1
1回答

当年话下

<div id="app">&nbsp; &nbsp; <el-button :type='type'>按钮</el-button>&nbsp; &nbsp; <button @click='change'>change</button></div><script>&nbsp; &nbsp; var vm = new Vue({&nbsp; &nbsp; &nbsp; &nbsp; el: "#app",&nbsp; &nbsp; &nbsp; &nbsp; data: {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; type: ''&nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; methods: {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; change: function() {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; this.type = 'primary'&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; })</script>
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript