Сообщество IT-специалистов
Ответы на любые вопросы об IT
Профессиональное развитие в IT
Удаленная работа для IT-специалистов
methods: { onClick1() { alert('button1 clicked'); }, onClick2() { this.$refs.button.click(); }, },
<button @click="onClick1" ref="button">button1: click me</button> <button @click="onClick2">button2: click button1</button>
TypeError: _this3.$refs.button.click is not a function
<button type="button" class="btn btn-green" @click="getAuth()">войти</button> <nuxt-link to="/users_area" ref="button"></nuxt-link>
getAuth() { authParams['email'] = this.singLogin; authParams['password'] = this.singPassword; //axios. запрос myObject.callApiPost('auth/login', authParams, '').then((res) => { this.newToken = res.data; document.cookie = 'token=' + this.newToken.data.token; this.notAuth = res.data.error; this.$root.$emit('isAuth', this.notAuth); if (!this.notAuth) { this.$refs.button.click(); $('.fancybox-close').click(); } }).catch((error) => { alert(error) this.errorAuth = true }); },
<button type="button" class="btn btn-green" @click="getAuth($event)">войти</button> <nuxt-link to="/users_area" ref="button"></nuxt-link>
getAuth() { let $this = $(e.target); authParams['email'] = this.singLogin; authParams['password'] = this.singPassword; //axios. запрос myObject.callApiPost('auth/login', authParams, '').then((res) => { this.newToken = res.data; document.cookie = 'token=' + this.newToken.data.token; this.notAuth = res.data.error; this.$root.$emit('isAuth', this.notAuth); if (!this.notAuth) { $this.$refs.button.click(); $('.fancybox-close').click(); } }).catch((error) => { alert(error) this.errorAuth = true }); },
TypeError: Cannot read property 'button' of undefined
this.$router.push(this.$refs.button.to)
<div @click="method">link</div> export default { ... methods: { method(e) { .... } } ... }