<template>
|
<div>
|
<!-- <input v-model="user" type="text">-->
|
<!-- <input v-model="message" type="text"><br>-->
|
<!-- <button @click="SendAll">发送</button>-->
|
<!-- <hr>-->
|
<!-- <ul>-->
|
<!-- <li v-for="(item, index) in msgList" :key="index">-->
|
<!-- {{ item.user }}: {{ item.msg }}-->
|
<!-- </li>-->
|
<!-- </ul>-->
|
|
<button @click="onClickButton">
|
手动发送
|
</button>
|
|
<div style="margin: 200px">{{ msg }}</div>
|
</div>
|
</template>
|
|
<script>
|
import * as signalR from '@microsoft/signalr'
|
|
export default {
|
data() {
|
return {
|
// connection: '',
|
// user: '',
|
// message: '',
|
// msgList: []
|
msg: ''
|
}
|
},
|
created() {
|
// this.init()
|
},
|
|
methods: {
|
|
onClickButton() {
|
this.$signalr.invoke('SendMessage', 'xx')// 用于手动发送消息的方式
|
.catch(function(err) {
|
return console.error(err)
|
})
|
}
|
//
|
// init() {
|
// this.connection = new signalR.HubConnectionBuilder()
|
// .withUrl('http://121.196.36.24:8019/chatHub', {})
|
// .configureLogging(signalR.LogLevel.Error)
|
// .build()
|
// this.connection.on('ReceiveMessage', data => {
|
// this.msgList.push(data)
|
// })
|
//
|
// this.connection.start().then(() => {
|
// if (window.Notification) {
|
// if (Notification.permission === 'granted') {
|
// console.log('允许通知')
|
// } else if (Notification.permission !== 'denied') {
|
// console.log('需要通知权限')
|
// Notification.requestPermission((permission) => {
|
// console.log('权限通知', permission)
|
// })
|
// } else if (Notification.permission === 'denied') {
|
// console.log('拒绝通知')
|
// }
|
// } else {
|
// console.error('浏览器不支持Notification')
|
// }
|
// console.log('连接成功')
|
// })
|
//
|
// this.connection.on('SendAll', (res) => {
|
// console.log(res, '收到消息')
|
// })
|
//
|
// // this.connection.start().then(() => {
|
// // this.connection.invoke('SendAll', '123', '我连上啦')
|
// // })
|
// },
|
// SendAll() {
|
// const params = {
|
// user: this.user,
|
// message: this.message
|
// }
|
// this.connection.invoke('SendAll', params)
|
// }
|
}
|
}
|
</script>
|
|
<style></style>
|