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