function - Vue3/Vite 中的方法
问题描述
有人可以告诉我如何在 Vite 中实现我的“del”方法吗?使用我的实际代码,我收到以下错误:
[Vue 警告]:在 <Home onVnodeUnmounted=fn ref=Ref< Proxy {...} >> at warn @ runtime-core.esm-bundler.js:38 logError @ runtime-core 处执行本机事件处理程序期间出现未处理错误。 esm-bundler.js:212 handleError @ runtime-core.esm-bundler.js:204 callWithErrorHandling @ runtime-core.esm-bundler.js:158 callWithAsyncErrorHandling @ runtime-core.esm-bundler.js:164 调用者@runtime- dom.esm-bundler.js:349 runtime-core.esm-bundler.js:218 Uncaught TypeError: Cannot read property 'tasks' of undefined
这些是我的代码中的相关部分:
<template>
<div>
<h1>Alle Aufgaben</h1>
<ul>
<li v-for="(task, index) in tasks" :class="{ 'done' : task.finish}">
<p>{{task.description}}</p>
<button class="doneChange" @click="doneChange(index)">✓</button>
<button class="del" @click="del(index)">X</button>
</li>
</ul>
</div>
</template>
<script>
import { ref, reactive, computed } from "vue";
export default {
setup() {
let tasks = [
{description: "Frühstücken", finish: true},
{description: "Lernen", finish: false},
{description: "Trainieren", finish: false},
{description: "Einkaufen", finish: false},
{description: "Mails", finish: false},
{description: "Abendessen", finish: false},
];
const del = (index) => this.tasks.splice(index,1);
return { tasks, del };
}
};
</script>
解决方案
任务应定义为 ref 属性并使用value
field 进行变异:
<script>
import { ref, reactive, computed } from "vue";
export default {
setup() {
let tasks = ref([
{description: "Frühstücken", finish: true},
{description: "Lernen", finish: false},
{description: "Trainieren", finish: false},
{description: "Einkaufen", finish: false},
{description: "Mails", finish: false},
{description: "Abendessen", finish: false},
]);
const del = (index) => tasks.value.splice(index,1);
return { tasks, del };
}
};
</script>
this
在设置挂钩中无法访问
推荐阅读
- python - 我正在使用 Tkinter 为外部程序编写 UI。如何将任何打印语句重定向到 tkinter 中的小部件?几乎就像一个实时日志
- excel - 某些计算机未完全加载 Excel vsto 插件
- twitter - 如何使用 Twitter API 检索一个国家/地区的 N 条最受欢迎的推文?
- c# - C#如何列出
接受列表 但不是 IList 创建集合时? - java - 关于使用eclipse在ubuntu最新版本中的java sql连接
- python - 如何更改此数据框的索引?
- c - C程序执行后立即退出,但它有一个while(1)循环
- asp.net-core-3.1 - ASP.NET Core 3.1 - 使用 .UseUrls() 设置应用程序 url 时“站点无法提供安全连接”
- python - 即将被弃用的 pandas.util.testing.assert_produces_warning 是否有替代方案?
- node.js - 我如何处理 package.json 中的错误?