最近在开发过程当中遇到一个问题。在节点上面写点击事件时,点击事件不执行。代码以下:vue
<!-- 操做 --> <el-table-column label="操做"> <template slot-scope="scope"> <span class="poi icon-hover f16 mr20" @click='scope.row.edit=!scope.row.edit'> <svg-icon :icon-class="scope.row.edit?'icon_edit_outline':'icon_save'"></svg-icon> </span> <span class="poi icon-hover f16"> <svg-icon icon-class="icon_delete"></svg-icon> </span> </template> </el-table-column> <!-- 操做 -->
这里面的click事件一直不执行,一开始觉得是点击事件没写对一直在找缘由,后面忽然想到会不会是数据不一样步的缘由的,由于edit字段是本身添加进去的字段,以下:svg
export default { name: 'strategic', data() { return { tableData: [{ 'pp_id': 4, 'brand_name': '1414', 'project_name': '得意', 'description': '的u会回来会', 'publish_time': '2018-07-23', 'is_used': 0 }] } }, components: { }, computed: { }, created() { this.initTableData() }, methods: { initTableData() { this.tableData.forEach(element => { element.edit = false }) } } }
以后我直接在数据里面加上edit字段,发现是可以同步数据的,代码以下:this
data() { return { tableData: [{ 'pp_id': 4, 'brand_name': '1414', 'project_name': '1414', 'description': '7588888888', 'publish_time': '2018-07-23', 'is_used': 0, 'edit': false }] } }
原来是在咱们使用vue进行开发,当生成vue示例后,再次给数据赋值时,有时候并不能自动更新到数据上去,这时候咱们就要经过$set来解决这个问题,解决代码以下:spa
initTableData() { this.tableData.forEach(element => { this.$set(element, 'edit', false) }) }
至此就解决啦。code