<script>
export default {
data() {
return {
awesome: true,
attrs:{"v-if":"awesome"}
}
}
}
</script>
<template>
<button @click="awesome = !awesome">toggle</button>
<h1 v-bind="attrs">Vue is awesome!</h1>
</template>
https://play.vuejs.org/#eNp9UctuwyAQ/BXKqZXyUJSb5UR9KIf20FZt1...
问题来源:https://stackoverflow.com/questions/41944054/reference-element-property-within-another-property
想要解决这个问题,又不想用v-for封装大改
首先
v-if
不是值绑定,所以不归v-bind
管我能想到的解决方案有两个
v-super-bind="{ 'v-if': 'awesome', '@click': () => {} }"
,具体怎么实现最好,我还没想好,看看有没有大佬知道PS 这个需求是挺有趣的,不过不建议在生产中使用