<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ??碼云GVP開源項目 12k star Uniapp+ElementUI 功能強大 支持多語言、二開方便! 廣告
                [TOC] ## TodoLIst [小程序-TodoList](http://www.hmoore.net/book/henputongderen/xiaochengxu/edit) [React](http://www.hmoore.net/book/henputongderen/react/edit) ## 功能介紹 > 將input輸入框里的內容打印到頁面上,可以輸入多條,并可以點擊刪除 > 知識點組件傳值 ![](https://box.kancloud.cn/b23d789c5d7f08540b4caea66e792280_506x418.gif) ## 知識細分 ### 1.使用組件 ``` 1.定義組件 name: "ListItem", 2.引入組件 import ListItem from "../components/ListItem"; 3.注冊組件 components: { ListItem }, 4.使用組件 <list-item v-for="(item, index) of list" :key="index" :content="item" :index="index" @delete="handleDelete" ></list-item> ``` ### 2.組件傳值 #### 父向子傳 ``` 1.傳值 <list-item v-for="(item, index) of list" :key="index" :content="item" :index="index" @delete="handleDelete" ></list-item> ``` ``` 2.接值 props: { index:Number, content:String }, ``` #### 子向父 ``` 1.傳值 綁定事件: @click="handleClick" methods: { handleClick(){ this.$emit('delete',this.index) } }, ``` ``` 2.接值 綁定事件:@delete="handleDelete" handleDelete(index) { this.list.splice(index, 1); } ``` ## 完整代碼 ### Home.vue ``` <template> <div class="home"> <input type="text" v-model="value"> <button @click="handleClick">確定</button> <ul> <list-item v-for="(item, index) of list" :key="index" :content="item" :index="index" @delete="handleDelete" ></list-item> </ul> </div> </template> <script> import ListItem from "../components/ListItem"; export default { name: "home", components: { ListItem }, data() { return { value: "hello", list: [] }; }, methods: { handleClick() { if (!this.list.includes(this.value)) { this.list.unshift(this.value); } }, handleDelete(index) { this.list.splice(index, 1); } } }; </script> ``` ### ListItem.vue ``` <template> <li @click="handleClick">{{content}}</li> </template> <script> export default{ name: "ListItem", props: { index:Number, content:String }, methods: { handleClick(){ this.$emit('delete',this.index) } }, } </script> ```
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看