Angular directive&&Vue component
小小的分享,加一下经验,大神请无视。 js angular.module('angularapp') .directive('dateSelect',function() { return { restrict: 'E',templateUrl: 'date-select.html',scope: { times: '=',query: '&' }, html date-select(times='time',query='query()') 这里我们看到了 直接用自定义标签 在其属性上面 进行数据传递,首先html整个作用域属于angularapp,所以传递时从本作用域到一个小的组件里去,自定义标签浏览器不识别,Angular 就会查询本身的directive这个估计是个数组形式的一个空间看看哪个dierective的名字跟这个匹配 然后执行directive就这样,我们的自定义标签被识别出来了,然后把内容注入到这个标签里面。 Vue Vue.component('todo-item',{ props: ['todo'],template: '<li>{{ todo.text }}</li>' }) var app7 = new Vue({ el: '#app-7',data: { groceryList: [ { text: '蔬菜' },{ text: '奶酪' },{ text: '随便其他什么人吃的东西' } ] } }) html <div id="app-7"> <ol> <!-- 现在我们为每个todo-item提供待办项对象 --> <!-- 待办项对象是变量,即其内容可以是动态的 --> <todo-item v-for="item in groceryList" v-bind:todo="item"></todo-item> </ol> </div>
(编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |