【发布时间】:2019-06-10 20:00:12
【问题描述】:
我有一个布局,我正在循环获取文本字段和一个按钮。我如何在按钮上添加一个功能,以便它只清除它各自的字段。 看看小提琴here。
<div id="app">
<h2>Each text with it's own state and clear should clear the respective
text fields</h2>
<ul v-for="todo in todos">
<li>
<input type="text" :placeholder="`${todo.text}`">
</li>
<li>
<input type="text" :placeholder="`${todo.text1}`">
</li>
<button>Clear</button>
</ul>
new Vue({
el: "#app",
data: {
todos: [
{ text: "Learn JavaScript", text1:"Hey" },
{ text: "Learn Vue", text1:"Hello" },
{ text: "Play around in JSFiddle", text1:"Ciao" },
{ text: "Build something awesome", text1:"Something"}
]
}
})
【问题讨论】:
-
您要清除占位符吗?
-
不是占位符,但是假设您应该能够输入当前占位符为“Learn JavaScript”的字段1,然后输入占位符为“嘿”的字段2,然后单击,这两个字段被清除。
-
请看我的回答
标签: javascript vue.js vuejs2 vue-component nuxt.js