vue添加,刪除內容


vue 提交添加內容,點擊刪除內容

1 html

<input v-model="inputValue" />
    <button @click="handClick">提交</button>
    <ul>
        <todo-item 
        v-for="(item,index) in list" :key="index"
        :content="item"
        :index='index'
        @delete="handdelete"
        ></todo-item>
    </ul>

2 js 

export default {
        data(){
            return{
                inputValue:'',
                list:[]
            }
        },
        methods:{
        //點擊提交添加內容 handClick(){
this.list.push(this.inputValue) this.inputValue='' }, // @delete="handdelete" 監聽子組件的方法 delete handdelete(index){ //接收子組件傳過來的index 進行刪除 this.list.splice(index,1) } } }

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM