2017-08-15 120 views

回答

0

你可以撰写你的属性为对象在计算性能:

computed: { 
    attributes() { 
    let attributes = {}; 
    if (this.someData) { 
     attributes['data-some'] = this.someData; 
    } 
    if (this.someOtherData) { 
     attributes['data-someother'] = this.someOtherData; 
    } 
    return attributes; 
    } 
} 

然后通过传递对象到v-bind指令绑定的属性到div:

<div v-bind="attributes"></div> 

这样,如果data-param的数据不存在,那么data-param属性将不会添加到attributes对象,并且不会绑定到div。

+0

不工作,没有任何呈现 –

+0

请注意,此指令在v-for模板中使用非静态数据 –

+1

然后请在您的问题中包含所有相关代码 – thanksd