- 28
- 0
<template>
<div>
<nav class="navbar navbar-default" role="navigation">
<div class="container-fluid">
<div class="navbar-header">
<a class="navbar-brand" href="#">ESN</a>
</div>
<button type="button" class="btn btn-default navbar-btn pull-right" v-on:click="logout()">
Logout
</button>
</div>
</nav>
<div class="weclome-msg" v-show="showWelcomeMessage">
<h1> Welcome {{ username }} to User home!!!</h1>
<p> Got it, go to see DSN directory </p>
<button v-on:click="seeDSNDir()">Yes</button>
</div>
<esndir v-show="showESNDir">
</esndir>
</div>
</template>
<script>
import {setCookie, getCookie} from '../assets/js/cookie.js'
import esndir from '@/components/esndir'
import axios from 'axios'
import io from 'socket.io-client'
export default {
data () {
return {
username: '',
showWelcomeMessage: true,
showESNDir: false
}
},
mounted () {
let cookieUsername = getCookie('username')
let _this = this
this.username = cookieUsername
if (cookieUsername === '') {
this.$router.push('/login')
}
this.socket = io.connect('http://localhost:3000')
this.socket.emit('userLogin', this.username)
this.socket.on('updateUser', function () {
_this.$ref.esndir.getCitizens()
})
},
methods: {
seeDSNDir () {
this.showWelcomeMessage = false
this.showESNDir = true
},
logout () {
let _this = this
axios.post('/apis/users/logout', {
params: {
username: _this.username
}
})
.then(function (response) {
console.log(response)
if (response.status === 200) { // remove current cookie
_this.socket.emit('userLogout')
setCookie('username', '', -1)
_this.$router.push('/')
}
})
.catch(function (error) {
console.log(error)
})
}
},
components: {
esndir
}
}
</script>
user.vue?9c2f:46 Uncaught TypeError: Cannot read property 'esndir' of undefined
at Socket.eval (user.vue?9c2f:46) - 共 0 条
- 全部回答
-
妞,给爷笑一个 普通会员 1楼
这个错误信息通常意味着你尝试访问一个未定义的属性或方法。在 Vue 中,我们可以通过
this指针来访问组件的属性和方法,但如果你尝试访问一个未定义的属性或方法,Vue 就会抛出这个错误。例如,如果你在
mounted生命周期钩子中尝试访问一个未定义的属性,那么就会出现这个错误。解决这个问题的一种方法是确保你在访问属性或方法之前,已经正确地获取了组件实例。例如:
javascript this.$refs.myComponent.$el.style.color = 'red';在这个例子中,我们首先使用
this.$refs.myComponent获取组件实例,然后使用this.$el访问myComponent组件的 DOM 元素。另一个解决这个问题的方法是在访问属性或方法之前,先检查它是否存在。例如:
javascript if ('esndir' in this.$refs.myComponent) { console.log(this.$refs.myComponent.esndir); } else { console.log('myComponent esndir not found'); }在这个例子中,我们首先检查
esndir属性是否存在,如果存在,我们就打印它的值,否则我们就打印一条错误消息。
- 扫一扫访问手机版
回答动态

- 神奇的四哥:发布了悬赏问题阿里云幻兽帕鲁服务器更新之后。服务器里面有部分玩家要重新创建角色是怎么回事啊?预计能赚取 0积分收益

- 神奇的四哥:发布了悬赏问题函数计算不同地域的是不能用内网吧?预计能赚取 0积分收益

- 神奇的四哥:发布了悬赏问题ARMS可以创建多个应用嘛?预计能赚取 0积分收益

- 神奇的四哥:发布了悬赏问题在ARMS如何申请加入公测呀?预计能赚取 0积分收益

- 神奇的四哥:发布了悬赏问题前端小程序接入这个arms具体是如何接入监控的,这个init方法在哪里进行添加?预计能赚取 0积分收益

- 神奇的四哥:发布了悬赏问题阿里云幻兽帕鲁服务器刚到期,是不是就不能再导出存档了呢?预计能赚取 0积分收益

- 神奇的四哥:发布了悬赏问题阿里云幻兽帕鲁服务器的游戏版本不兼容 尝试更新怎么解决?预计能赚取 0积分收益

- 神奇的四哥:发布了悬赏问题阿里云幻兽帕鲁服务器服务器升级以后 就链接不上了,怎么办?预计能赚取 0积分收益

- 神奇的四哥:发布了悬赏问题阿里云幻兽帕鲁服务器转移以后服务器进不去了,怎么解决?预计能赚取 0积分收益

- 神奇的四哥:发布了悬赏问题阿里云幻兽帕鲁服务器修改参数后游戏进入不了,是什么情况?预计能赚取 0积分收益
- 回到顶部
- 回到顶部

