What I bring to you this time is how to use vue in scope. We all know that vue slot can pass any attribute or html element , but when calling the component In the page, we can use template scope="props" to get the attribute value on the slot. The obtained value is an object. This article will give you a detailed analysis.
It has been said above that the scope obtains an object. What does it mean? Let’s look at a simple demo first to understand~
<!DOCTYPE html> <html> <head> <title>Vue-scope的理解</title> <script src="./libs/vue.js"></script> <link rel="stylesheet" href="./css/index.css" rel="external nofollow" /> <script src="./js/scope.js"></script> </head> <body> <div id="app"> <tb-list :data="data"> <template scope="scope"> <div class="info" :s="JSON.stringify(scope)"> <p>姓名:{{scope.row.name}}</p> <p>年龄: {{scope.row.age}}</p> <p>性别: {{scope.row.sex}}</p> <p>索引:{{scope.$index}}</p> </div> </template> </tb-list> </div> <script id="tb-list" type="text/x-template"> <ul> <li v-for="(item, index) in data"> <slot :row="item" :$index="index"></slot> </li> </ul> </script> <script type="text/javascript"> new Vue({ el: '#app', data() { return { data: [ { name: 'kongzhi1', age: '29', sex: 'man' }, { name: 'kongzhi2', age: '30', sex: 'woman' } ] } }, methods: { } }); </script> </body> </html>
js code is as follows:
##
Vue.component('tb-list', { template: '#tb-list', props: { data: { type: Array, required: true } }, data() { return { } }, beforeMount() { }, mounted() { }, methods: { } });
js to achieve imitation window system calendar effect
How nvm manages different versions of nodes
The above is the detailed content of How to use vue in scope. For more information, please follow other related articles on the PHP Chinese website!