<!--<template>-->
|
<!-- <div class="home">-->
|
<!-- <h1>前端演示SignalR</h1>-->
|
<!-- <input v-model="user" type="text">-->
|
<!-- <input v-model="message" type="text">-->
|
<!-- <button @click="sendAll">发送全部</button>-->
|
<!-- <button @click="sendOwn">对自己发送</button>-->
|
<!-- <button @click="sendOther">对其他发送</button>-->
|
<!-- <div>-->
|
<!-- <ul v-for="(item, index) in messages" :key="index + 'itemMessage'">-->
|
<!-- <li>{{ item.user }} says {{ item.message }}</li>-->
|
<!-- </ul>-->
|
<!-- </div>-->
|
<!-- </div>-->
|
<!--</template>-->
|
|
<!--<script>-->
|
<!--// @ is an alias to /src-->
|
<!--import * as signalR from '@aspnet/signalr'-->
|
<!--export default {-->
|
<!-- name: 'Home',-->
|
<!-- components: {},-->
|
<!-- data() {-->
|
<!-- return {-->
|
<!-- user: 's2', // 用户-->
|
<!-- message: '22222', // 消息-->
|
<!-- connection: '', // signalr连接-->
|
<!-- messages: [] // 返回消息-->
|
<!-- }-->
|
<!-- },-->
|
<!-- created: function() {-->
|
<!-- const thisVue = this-->
|
<!-- this.connection = new signalR.HubConnectionBuilder()-->
|
<!-- .withUrl('http://121.196.36.24:8019/chatHub', {-->
|
<!-- // skipNegotiation: true,-->
|
<!-- // transport: signalR.HttpTransportType.WebSockets-->
|
<!-- })-->
|
<!-- .configureLogging(signalR.LogLevel.Information)-->
|
<!-- .build()-->
|
|
<!-- console.log(this.connection, 1)-->
|
|
<!-- this.connection.on('ReceiveMessage', function(user, message) {-->
|
<!-- debugger-->
|
<!-- thisVue.messages.push({ user, message })-->
|
<!-- console.log({ user, message })-->
|
<!-- })-->
|
<!-- this.connection.on('ReceiveCaller', function(message) {-->
|
<!-- debugger-->
|
<!-- const user = '自己' // 这里为了push不报错,我就弄了一个默认值。-->
|
<!-- thisVue.messages.push({ user, message })-->
|
<!-- console.log({ user, message })-->
|
<!-- })-->
|
<!-- this.connection.start()-->
|
<!-- },-->
|
<!-- methods: {-->
|
<!-- // 给全部发送消息-->
|
<!-- sendAll: function() {-->
|
<!-- this.connection-->
|
<!-- .invoke('SendMessage', this.user, this.message)-->
|
<!-- .catch(function(err) {-->
|
<!-- return console.error(err)-->
|
<!-- })-->
|
<!-- },-->
|
<!-- // 只给自己发送消息-->
|
<!-- sendOwn: function() {-->
|
<!-- this.connection-->
|
<!-- .invoke('SendMessageCaller', this.message)-->
|
<!-- .catch(function(err) {-->
|
<!-- return console.error(err)-->
|
<!-- })-->
|
<!-- },-->
|
|
<!-- // 给其他人员发送消息-->
|
<!-- sendOther: function() {-->
|
<!-- this.connection-->
|
<!-- .invoke('SendMessageOther', this.user, this.message)-->
|
<!-- .catch(function(err) {-->
|
<!-- return console.error(err)-->
|
<!-- })-->
|
<!-- }-->
|
<!-- }-->
|
<!--}-->
|
<!--</script>-->
|