以下是代码:
const signalR = require("@microsoft/signalr");
export default {
name: "mainFrame",
data(){
return{
connection: "",
user: "",
message: "",
msgList: []
}
},
methods:{
init() {
this.connection = new signalR.HubConnectionBuilder()
.withUrl("http://111.111.1.111:11111/zxc", {})
.configureLogging(signalR.LogLevel.Error)
.build();
this.connection.on("ReceiveMessage", data => {
this.msgList.push(data);
});
this.connection.start();
},
},
created(){
this.init()
}
别再create里斯奥用init再mounted里试试。
created:在模板渲染成html前调用,即通常初始化某些属性值,然后再渲染成视图。
mounted:在模板渲染成html后调用,通常是初始化页面完成后,再对html的dom节点进行