Vue 中prop的使用


<div id="app">
            <button-counter  v-for="item in todos" :my-title="item.text">
            </button-counter>
        </div>
        <script type="text/javascript">
            // 作用域插槽
            Vue.component('button-counter', {
              data: function () {
                return {
                  count: 0
                }
              },
              props:['myTitle'],
              template: '<button v-on:click="count++">{{myTitle}}---You clicked me {{ count }} times.</button>'
            })
            var app = new Vue({
                el: "#app",
                data: {
                    name: "岔道口",
                    todos: [{
                            text: "A",
                            id: 1,
                            isTrue: true
                        },
                        {
                            text: "B",
                            id: 2,
                            isTrue: true
                        },
                        {
                            text: "C",
                            id: 3,
                            isTrue: false
                        },
                        {
                            text: "D",
                            id: 4,
                            isTrue: true
                        },
                    ],
                },



            })
        </script>

 


免責聲明!

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



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