如果是cdn的方式使用vue直接在浏览器中执行,父子组件之间的通讯代码如下:
<!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 () {
},
methods: {
replyit(toid,touser){
this.$emit('replyit', [toid,touser]);
}
}
});
new Vue({
el: '#app',
components: { // 不需要注册也能使用
},
mounted: function () {
console.log("vue挂载完成");
},
data: {
touser:"",
toid:"",
comments: [{
"id": 1,
"pid": 0,
"nickname": "张三",
"content": "你们好",
"createTime": "2020-04-12T06:32:20.613+0000",
"replyComments": [{
"id": 2,
"pid": 1,
"nickname": "李四",
"content": "你好",
"createTime": "2020-04-12T06:32:31.699+0000",
"replyComments": []
}]
},
{
"id": 3,
"pid": 0,
"nickname": "王五",
"content": "猪吗?",
"createTime": "2020-04-12T06:34:37.146+0000",
"replyComments": [{
"id": 4,
"pid": 3,
"nickname": "赵六",
"content": "??",
"createTime": "2020-04-12T07:03:47.873+0000",
"replyComments": [{
"id": 5,
"pid": 4,
"nickname": "老李",
"content": "你们在耍啥",
"createTime": "2020-04-12T07:03:47.873+0000",
"replyComments": []
}]
}]
},
]
},
methods: {
replyit(data){
this.touser="回复"+data[1];
this.toid=data[0];
}
}
});
</script>
</body>
</html>
网友回复
- threejs如何做个三维搭积木的游戏?
- three如何实现标记多个起始路过地点位置后选择旅行工具(飞机汽车高铁等),最后三维模拟行驶动画导出mp4?
- ai实时驱动的3d数字人可视频聊天的开源技术有吗
- swoole+phpfpm如何实现不同域名指向不同目录的多租户模式?
- 如何用go替换nginx实现请求phpfpm解析运行php脚本?
- 有没有浏览器离线运行进行各种文档、图片、视频格式转换的开源工具?
- 如何使用go语言搭建一个web防火墙?
- linux如何检测特定网络协议比如http协议中报文是否包含特点关键词并阻止返回给客户?
- 如果在nginx外过滤包含某些关键词的网页并阻止打开?
- 程序员怎么做副业赚钱?



 
				 
			 
			 
				 
			