原 Vue学习
|-原 currentIndex.value 变化后,如果视图(模板)上没有绑定currentIndex,就不会更新视图
currentIndex.value 变化后,如果视图上没有绑定currentIndex,就不会更新视图对吧,除了:class="{ 'active': currentIndex === index }" ,还有哪些情况的绑定
你的理解非常准确!在 Vue 中,如果视图(模板)上没有绑定某个响应式变量,那么即使这个变量的值发生了改变,Vue 也不会去更新对应的 DOM。这就是 Vue 依赖追踪机制的高效之处。
除了你提到的 :class="{ 'active': currentIndex === index }",只要是在 <template> 中“消费”了 currentIndex 的地方,都会建立依赖关系。以下是几种常见的绑定情况:
1. 文本插值(最常见)
直接在双大括号中使用变量,Vue 会监听它的变化并更新文本内容。
<p>当前显示的是第 {{ currentIndex }} 条公告</p>
2. 其他 HTML 属性绑定 (v-bind:)
你可以把 currentIndex 用在任何合法的 HTML 属性上:...
浏览更多内容请先登录。
立即注册
更新于:2026-06-08 15:51:50
相关内容
Mysql错误1366的解决办法:Incorrect string value: '\xF0\x9F...' for ...
关于四字节字符入库时错误的解决方案(Incorrect string value: '\xF0\x9F...
Yii2测了下全文索引,好像是
php报错 Error: Variable 'sql_mode' can't be set to the value of 'M...
PHP报错:Constants may only evaluate to scalar values
推荐内容