当前位置: 首页 > wzjs >正文

网站建设运营方案厦门seo屈兴东

网站建设运营方案,厦门seo屈兴东,seo搜索引擎优化5,通辽建设网站结果 不废话,直接上结果: 方法arr.pusharr.splicearr[i] …arr …arr.length 0模板✔️✔️✔️✔️✔️watch(arr) ✖️✖️✖️✔️✖️watch(arr.value)✔️✔️✔️✖️✔️watch(arr, { deep: true })✔️✔️✔️✔️✔️watch(arr.value.len…

结果

不废话,直接上结果:

方法arr.pusharr.splicearr[i] = …arr = …arr.length = 0
模板✔️✔️✔️✔️✔️
watch(arr) ✖️✖️✖️✔️✖️
watch(arr.value)✔️✔️✔️✖️✔️
watch(arr, { deep: true })✔️✔️✔️✔️✔️
watch(arr.value.length)⚠️⚠️⚠️⚠️⚠️
watch(() => arr.value)✖️✖️✖️✔️✖️
watch(() => arr.value.length)✔️✔️✖️✔️*✔️*

从结果来看,watch(arr, { deep: true }) 最为保险,与模板行为一致。但是 deep watch 太大的对象可能会影响性能。

你可以根据上面的表格来确定到底用哪一种方法。

说明:

  1. ✔️ 表示这一列的操作能触发这一行的 watch,✖️ 同理。
  2. ⚠️ 表示报错。
  3. 列头上的操作省去了 .value。因为是在模板中执行的代码,不用加 .value

(* 见下方解释)

解释

  1. watch(arr):监听的是 ref 的值,也就是数组的引用。只有整个数组被替换时才会触发。
  2. watch(arr.value):ref 中的非原始值底层会自动改用 reactive,因此 watch arr.value 相当于 watch 底层的 reactive 对象。当数组被整个替换后,watch 的依旧是原来的数组,而不是新的数组,所以 arr = ... 不会被触发。
  3. watch(arr, { deep: true }):相当于 1 和 2 的组合。
  4. watch(arr.value.length)arr.value.length 是个数字,不是 ref 对象、reactive 对象或者 getter 函数,因此这段代码根本无法执行。
  5. watch(() => arr.value):和 1 是一样的。这点在 Vue3 文档中也有提及。
  6. watch(() => arr.value.length):4 的正确书写版。因为 watch 的是 arr 的长度,不管 arr 发生了什么,只要长度变了就会触发。测试中的 arr = ... 恰好新旧数组长度不一致,所以可以触发。

测试代码

<script setup>
import { ref, watch } from 'vue'const counter = ref(0);const arr = ref([]);
const _watch = ref([]);
const _watchValue = ref([]);
const _watchDeep = ref([]);
const _watchLength = ref('[Vue warn]: Invalid watch source:  0 A watch source can only be a getter/effect function, a ref, a reactive object, or an array of these types. ');
const _watchGetter = ref([]);
const _watchGetterLength = ref([]);   watch(arr, () => _watch.value = [...arr.value]);
watch(arr.value, () => _watchValue.value = [...arr.value]);
watch(arr, () => _watchDeep.value = [...arr.value], { deep: true });
// watch(arr.value.length, () => _watchLength.value = [...arr.value]);
watch(() => arr.value, () => _watchGetter.value = [...arr.value]);
watch(() => arr.value.length, () => _watchGetterLength.value = [...arr.value]);
</script><template><table><tbody><tr><td>模板</td><td>{{ arr }}</td></tr><tr><td>watch(arr)</td><td>{{ _watch }}</td></tr><tr><td>watch(arr.value)</td><td>{{ _watchValue }}</td></tr><tr><td>watch(arr, { deep: true })</td><td>{{ _watchDeep }}</td></tr><tr><td>arr.value.length</td><td>{{ _watchLength }}</td></tr><tr><td>watch(() => arr.value)</td><td>{{ _watchGetter }}</td></tr><tr><td>watch(() => arr.value.length)</td><td>{{ _watchGetterLength }}</td></tr></tbody></table><div class="button-group"><button @click="arr.push(counter++)">arr.push(i)</button><button @click="arr.splice(0, 1)">arr.splice(0, 1)</button><button @click="arr[0] = counter++">arr[0] = i</button><button @click="arr = [counter]">arr = [i]</button><button @click="arr.length = 0">arr.length = 0</button></div>
</template><style>
/* 样式由 Claude Sonnet 3.5 完成 */
* {font-family: consolas;
}
table {border-collapse: collapse;margin: 20px 0;width: 100%;max-width: 800px;
}td {border: 1px solid #ddd;padding: 8px 12px;
}td:first-child {font-weight: bold;background-color: #f5f5f5;width: 300px;
}.button-group {margin: 20px 0;
}button {margin-right: 10px;padding: 8px 16px;background-color: #4CAF50;color: white;border: none;border-radius: 4px;cursor: pointer;
}button:hover {background-color: #45a049;
}button:last-child {margin-right: 0;
}
</style>
http://www.dtcms.com/wzjs/244939.html

相关文章:

  • 高并发网站建设新闻发稿平台
  • 电商网站的分辨率东莞网络营销平台
  • wordpress跟bootstrapseo搜索引擎优化内容
  • 个人网站建设设计长春网站制作推广
  • 广东高端网站建设公司软文是什么
  • 网站后台改网页底色点点站长工具
  • 设计师网站外网太原百度seo排名软件
  • 怎么做新网站快手seo关键词优化
  • 建站属于什么行业超级外链工具有用吗
  • 青岛网络推广公司成都爱站网seo站长查询工具
  • 用Axure做的网站原型百度云郑州做网站
  • 网站快速查找百度推广登录入口
  • 一流的山西网站建设百度小程序入口
  • 青岛模板网站农产品网络营销策划书
  • 网站建设报告书范文百度投诉中心电话
  • 淘宝有做网站吗谷歌关键词搜索
  • 网站建设团队架构雅思培训班价格一览表
  • 网站建设服务培训学校招生方案
  • 赞美对方公司网站做的好的日语正规网络推广服务
  • 国外做giveaway的网站简述网络营销的含义
  • b2c商城网站建设目的seo检测优化
  • 茶企业网站自己创建网站
  • ruhe用dw做网站写软文推广
  • 游戏网站的监管由谁来做seo关键字优化价格
  • 怎么给网站 做排名制作网页的流程步骤
  • 主题网络设计图幼儿园大班百度seo自动优化
  • 哪些网站是java做的中山谷歌推广
  • 视频类网站备案国内企业网站模板
  • 机器配件做外贸上什么网站网络营销推广处点
  • dede网站入侵教程网络零售的优势有哪些