网站推广策略含义,惠州网站建设制作公司,咸阳网站制作建设,产教融合平台建设网站1、问题
开发过程中有个需求是遍历列表绘制div,div的样式是后端接口传来的#xff0c;一开始这种写法#xff0c;#xff1a;style“formatStyle(item)”#xff0c;写在了模板中
这样写发现一个问题#xff0c;只要页面发生重绘#xff0c;比如页面输入框输入数字一开始这种写法style“formatStyle(item)”写在了模板中
这样写发现一个问题只要页面发生重绘比如页面输入框输入数字formatStyle 会重复执行太耗性能
2、解决
在拿到列表数据时给列表每个对象加个iStyle属性 div v-foritem in copylayerList :keyitem.iddiv classlayer_div :styleitem.iStyle clickeditLaywer(item)span classlayer_div_text{{item.name}}/span/div/div我这里是访问接口拿到数据后遍历数组给数组对象添加属性 http.get(/XXX, this.listQuery).then((res) {if (res.code 200) {this.copylayerList [...res.data.list];this.copylayerList.map((item) {item.iStyle this.formatStyle(item)})}});