vue.js - v-if 切换消息导致无限更新循环 Vue 警告
问题描述
我正在学习Vue Native,特别是v-if
条件,并且有以下测试代码:
<template>
<view class="container">
<button :on-press="seen = !seen" title="Click to Toggle Message Visibility" />
<text v-if="seen">Now you see the message</text>
</view>
</template>
<script>
export default {
data: function() {
return {
seen: false
};
}
};
</script>
<style>
.container {
flex: 1;
align-items: center;
justify-content: center;
}
</style>
它应该让用户单击按钮并且消息将出现/消失。但是,它会导致以下错误:
console.error: "[Vue warn]: You may have an infinite update loop in a component render function.
(found in )"
应该如何修改代码以使其正常工作?
解决方案
同意接受的答案。另外,:on-press
是属性绑定,但是使用v-on
事件绑定不会有这个死循环的问题,比如<button v-on:click="seen = !seen" title="Click to Toggle Message Visibility" />
. 这可能就是您从中获得此内联方法用法seen = !seen
的地方。
推荐阅读
- asp.net-core - 接收多部分表单数据 json 参数 null
- java - MongoTemplate 拉取查询
- php - 我可以使用 PHP 客户端(或根本不使用!)在 Google Sheets api v4 中按标题访问电子表格吗?
- c++ - 由于图像质量差,使用 OpenCV 从无人机拼接图像时出现问题
- python - 登录 GCP 或本地
- sql - Hive 删除记录的计数
- python - 如何删除具有相似名称的 Python 文件?
- python - 如何从 tensorflow 数据集中选择特定列?
- python - 部署后 Django 登录不起作用 (pythonanywhere.com)
- r - 如何在 stop() 函数的错误消息中获取 data.table?