Vue.js Vuejs在已安装的生命周期挂钩中的功能
我希望在Vuejs代码中的Vue.js Vuejs在已安装的生命周期挂钩中的功能,vue.js,vuetify.js,Vue.js,Vuetify.js,我希望在Vuejs代码中的挂载的生命周期挂钩期间调用我的hideMe()函数。目前不是,我不明白为什么 我的代码如下: export default { data() { return { show: "initial" } }, methods: { hideMe() { if(this.$vuetify.breakpoint.name == 'xs') { console.log("When is this rend
挂载的生命周期挂钩期间调用我的hideMe()
函数。目前不是,我不明白为什么
我的代码如下:
export default {
data() {
return {
show: "initial"
}
},
methods: {
hideMe() {
if(this.$vuetify.breakpoint.name == 'xs') {
console.log("When is this rendered? " + this.$vuetify.breakpoint.name == 'xs');
this.show = "none";
}
}
},
mounted() {
this.hideme();
console.log("This is a breakpoint name " + this.$vuetify.breakpoint.name);
console.log(this.show);
},
computed: {
imageHeight () {
switch (this.$vuetify.breakpoint.name) {
case 'xs': return '450px';
case 'sm': return '500px';
case 'md': return '500px';
case 'lg': return '540px';
case 'xl': return '540px';
}
}
}
};
您的逻辑正确,请尝试:
methods: {
hideMe() {
if(this.$vuetify.breakpoint.name == 'xs') {
console.log("When is this rendered? " + this.$vuetify.breakpoint.name == 'xs');
this.show = "none";
}
}
},
mounted() {
this.hideMe();
console.log("This is a breakpoint name " + this.$vuetify.breakpoint.name);
console.log(this.show);
},
注意:声明:
console.log("When is this rendered? " + this.$vuetify.breakpoint.name == 'xs');
只需打印false
,因为它的工作方式如下
console.log( ("When is this rendered? " + this.$vuetify.breakpoint.name) == 'xs');
添加()
s时修复此问题:
哇!我说不出有什么区别!哈什么是秘密,因为它是有效的!我在回答中做了一个新的注解。另一个问题。啊,“hideme”函数的问题是你调用的是this.hideme()
,而不是this.hideme()
(注意M
)哈,是的。。。有时别忘了休息一下
console.log("When is this rendered? " + (this.$vuetify.breakpoint.name == 'xs'));