Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vue.js/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Vue.js 如何在NuxtJS中上下文可用时立即挂接?_Vue.js_Nuxt.js_Hook - Fatal编程技术网

Vue.js 如何在NuxtJS中上下文可用时立即挂接?

Vue.js 如何在NuxtJS中上下文可用时立即挂接?,vue.js,nuxt.js,hook,Vue.js,Nuxt.js,Hook,在NuxtJS应用程序(ssr:true,target:'static')中,我需要在浏览器中呈现页面时执行一个方法。 细节:我想改变颜色,但我想防止白色闪光 我试过: mounted() { this.changeColor(); }, created() { this.changeColor(); }, …但问题是,当颜色改变时,页面内容已经显示…它会闪烁!(与beforeMount()相同 …我试过: mounted() { this.changeColor()

在NuxtJS应用程序(
ssr:true,target:'static'
)中,我需要在浏览器中呈现页面时执行一个方法。 细节:我想改变颜色,但我想防止白色闪光

我试过:

mounted() {
    this.changeColor();
},
created() {
    this.changeColor();
},
…但问题是,当颜色改变时,页面内容已经显示…它会闪烁!(与
beforeMount()相同

…我试过:

mounted() {
    this.changeColor();
},
created() {
    this.changeColor();
},
…问题是它什么也不做,因为此时不存在
this.changeColor()


如何做到这一点?

我会尝试在组件的上下文之外使
changeColor
成为静态的(这将包括删除对组件道具/数据的任何依赖),以便可以随时调用它。如果你提供复制品的链接,我可能会提供更好的解决方案。