fix: WebSocketDemo中获取用户异常
This commit is contained in:
@@ -12,6 +12,7 @@
|
|||||||
</template>
|
</template>
|
||||||
<script>
|
<script>
|
||||||
import CsWsClient from '@/utils/CsWsClient'
|
import CsWsClient from '@/utils/CsWsClient'
|
||||||
|
import { mapGetters } from 'vuex'
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
data() {
|
data() {
|
||||||
@@ -21,7 +22,11 @@ export default {
|
|||||||
responseTxt: ''
|
responseTxt: ''
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
// mounted() {},
|
computed: {
|
||||||
|
...mapGetters([
|
||||||
|
'user'
|
||||||
|
])
|
||||||
|
},
|
||||||
destroyed() {
|
destroyed() {
|
||||||
if (this.client) {
|
if (this.client) {
|
||||||
this.client.close()
|
this.client.close()
|
||||||
@@ -29,10 +34,9 @@ export default {
|
|||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
onConnectClick() {
|
onConnectClick() {
|
||||||
// 获取mapGetters中的值
|
|
||||||
// console.error('userInfo', this.user)
|
|
||||||
const that = this
|
const that = this
|
||||||
that.client = new CsWsClient(that)
|
// console.error('userInfo', that.user)
|
||||||
|
that.client = new CsWsClient(that.user.username)
|
||||||
that.client.connect(function(event) {
|
that.client.connect(function(event) {
|
||||||
console.info('=============== MyWebSocket:event', event)
|
console.info('=============== MyWebSocket:event', event)
|
||||||
}, function(msgEvent) {
|
}, function(msgEvent) {
|
||||||
|
|||||||
Reference in New Issue
Block a user