请问vue采用cdn直接在浏览器执行的完整component组件怎么写?还有父子组件之间的传值?
网友回复
使用 Vue.component来声明一个组件,子组件与父组件之间的通讯方式通过props与$emit来实现。
完整代码
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width,initial-scale=1.0,maximum=1.0,minimum=1.0,user-scalable=0" /> <script type="text/javascript" src="//repo.bfw.wiki/bfwrepo/js/vue@2.6.1-dev.js"></script> <style> .comment-box{ padding: 5px 10px; border: 1px solid grey; margin:5px; } .reply{ color: red; font-weight: bold; } </style> </head> <body> <div id="app"> <div id="comment"> <Reply :commentdata="comments" v-on:replyit="replyit"></Reply> </div> <form><input :placeholder="touser" id="replycontent" /> <input type="hidden" id="toid" :value="toid" /><input type="button" value="回复" /></form> </div> <script type="text/javascript"> Vue.component('Reply',{ template: '<div><div class="comment-box" v-for="item in commentdata"><span>{{item.nickname}}说</span> <span>{{item.content}}</span> <span @click="replyit(item.id,item.nickname)" class="reply">回复</span><Reply v-bind="$attrs" v-on="$listeners" v-if="item.replyComments" :commentdata="item.replyComments" ></Reply></div></div>', props: ['commentdata'], data: function () { return { }; }, mounted: function () { ...
点击查看剩余70%