課程
/前端開發
/Vue.js
/vue.js入門基礎
我知道直接在控制臺里刪除后刷新能行,還有沒有其它什么方法
2018-09-07
源自:vue.js入門基礎 2-3
正在回答
localStorage 有個 clear() 可以刪除所有的 localStorage...
不過這個應該是做成刪除某個待辦事項, 在items移除該元素就行了吧。
注意:我是把vue.js通過<scrpt>引入的
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>todolist</title>
<script src="./vue.js"></script>
</head>
<body>
<div id="root">
<div>
<input v-model="value"/>
<button v-on:click="submit">提交 </button>
</div>
<ul>
<todo?
v-for="(item, index) of list":key="index"
:content="item"
:index="index"
v-on:delete="handleDelete"
></todo>
</ul>
<script>
Vue.component('todo', {
props:['content', 'index'],
template:'<li @click="handleClick">{{content}}</li>',
methods:{
handleClick:function(){
this.$emit('delete', this.index)
}
})
new Vue({
el:"#root",
data:{
value:"",
list:[]
},
submit:function(){
this.list.push(this.value);
this.value="";
handleDelete:function(index){
this.list.splice(index, 1)
</script>
</body>
</html>
舉報
本門為vuejs入門教程,詳細的講解加實戰,可以幫你進入vuejs的大門
Copyright ? 2025 imooc.com All Rights Reserved | 京ICP備12003892號-11 京公網安備11010802030151號
購課補貼聯系客服咨詢優惠詳情
慕課網APP您的移動學習伙伴
掃描二維碼關注慕課網微信公眾號
2018-09-12
localStorage 有個 clear() 可以刪除所有的 localStorage...
不過這個應該是做成刪除某個待辦事項, 在items移除該元素就行了吧。
2018-09-10
注意:我是把vue.js通過<scrpt>引入的
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>todolist</title>
<script src="./vue.js"></script>
</head>
<body>
<div id="root">
<div>
<input v-model="value"/>
<button v-on:click="submit">提交 </button>
</div>
<ul>
<todo?
v-for="(item, index) of list":key="index"
:content="item"
:index="index"
v-on:delete="handleDelete"
></todo>
</ul>
</div>
<script>
Vue.component('todo', {
props:['content', 'index'],
template:'<li @click="handleClick">{{content}}</li>',
methods:{
handleClick:function(){
this.$emit('delete', this.index)
}
}
})
new Vue({
el:"#root",
data:{
value:"",
list:[]
},
methods:{
submit:function(){
this.list.push(this.value);
this.value="";
},
handleDelete:function(index){
this.list.splice(index, 1)
}
}
})
</script>
</body>
</html>