在点击事件修改phoneView的值之后,发现渲染的dom并没有修改。经过多次测试,发现在slot内部phoneView的值并没有改变,或者说改变后,又变回去了
<div>
<el-table ...>
<el-table-column ...>
<template slot="header">
<div>
<span @click="phoneView = !phoneView">手机号码</span>
<span v-if="phoneView">1</span>
<span v-else>2</span>
</div>
</template>
</el-table-column>
</el-table>
</div>
解决方法
将slot="header"改成#header就可以了,如:
<div>
<el-table ...>
<el-table-column ...>
<template #header>
<div>
<span @click="phoneView = !phoneView">手机号码</span>
<span v-if="phoneView">1</span>
<span v-else>2</span>
</div>
</template>
</el-table-column>
</el-table>
</div>