laravel - 我想集成一个 laravel 广播来实时更新一个 html 属性
问题描述
进度条的 HTML
<div class="ui fluid inverted segment" id="app">
<div class="ui small header">ONGOING GRANT ANALYSIS </div>
<div class="ui indicating big progress" id="grantprogress" :data-total="total" :data-value="value" >
<div class="bar">
<div class="progress" ></div>
</div>
</div>
</div>
JS激活它
$('#grantprogress').progress();
VUEJS 聆听频道
const app = new Vue({
el: '#app',
created(){
Echo.channel('progress-bar-socket')
.listen('ProgressUpdaterEvent', (e) => {
this.value = e["update"];
console.log(e["update"]);
});
},
data: {
total: 1500000,
value: e["update"]
}
});
我有一个 Laravel 事件,当我的网站上发生某些事情时会发送它,它会根据我的数据库中的一些记录计数进行更新。我使用记录计数实时更新进度条。我可以在控制台中获取记录计数,但将其作为属性绑定到进度条的 html 元素会给我带来问题。
解决方案
:data-value="value"
基本上是说属性data-value
应该设置为对象value
中的任何内容data
。
要更新value
你只需要做的财产
this.value = 'the new value of the property';
IE
created() {
Echo.channel('progress-bar-socket')
.listen('ProgressUpdaterEvent', (e) => {
this.value = e["update"];
});
},
我建议你看看系列教程
属性更改时,进度条的值不会自动更新。查看文档,更新您可以使用的值:
$('#grantprogress').progress('set progress', this.value);
所以,你可以设置一个水,value
或者直接把它放在你的监听器回调中:
Echo.channel('progress-bar-socket')
.listen('ProgressUpdaterEvent', e => {
$('#grantprogress').progress('set progress', e.update);
});
推荐阅读
- networking - 计算路线汇总的最佳方法是什么?
- scala - 尝试在 mapPartitionsWithIndex 中广播时出现 NullPointerException
- r - 删除列中前 n 行的字符串的第一个数字
- jmeter - 控制器时无法循环使用 2 层
- python - 是否可以在模型训练时“实时”查看张量板(分布/直方图)
- javascript - 您可以为每个端点配置 NestJS 缓存 TTL 吗?
- javascript - 饼图的标签文本未出现
- c - USART1中断IRQHandler如何接收字符串
- swift - Swift 中的协议
- python - 如何处理从不同目录导入的 .py 文件的路径?