文章博客

技术团队文档示例


【vue】声明响应式属性

<h4>声明响应式属性</h4> <hr /> <p>由于vue不允许动态添加根级响应式属性,所以你必须在初始化实例前声明所有的根级属性,哪怕只是一个空值。</p> <pre><code>var vm = new Vue({ data: { // 声明 message 为一个空值字符串 message: '' }, template: '&lt;div&gt;{{ message }}&lt;/div&gt;' }) // 之后设置 `message` vm.message = 'Hello!'</code></pre> <h4>vm.$nextTick()</h4> <hr /> <p>在组件内使用 vm.$nextTick() 实例方法特别方便,因为它不需要全局 Vue,并且回调函数中的 this 将自动绑定到当前的 Vue 实例上:</p> <pre><code>methods: { updateMessage: function () { this.message = '已更新' console.log(this.$el.textContent) // =&gt; '未更新' this.$nextTick(function () { console.log(this.$el.textContent) // =&gt; '已更新' }) } }</code></pre>

页面列表

ITEM_HTML