在我的页面中,我有以下头部属性
export default{
head: {
bodyAttrs: {
class: 'parallax-visible'
}
},
methods:{
modifyHeadTags(){
//here change the body class
//eg set like this.head.bodyAttrs.class="newclass"
console.log("head is", this.head); //this is undefined
}
}
现在上面的函数记录头未定义,我如何以编程方式修改这些头标签
所以在函数中我希望做类似的事情
this.head.bodyAttrs.class = "new class" //this one
最佳答案
head
在 this.$options
中可用,以及 components
、methods
和 中的其他属性>vueJs
您可以使用方法函数内的 this.$options.head
访问 head。
所以你需要在函数内做类似的事情,
this.$options.head.bodyAttrs.class="newclass" //make sure bodyAttrs is defined in head object
关于javascript - nuxtjs 以编程方式修改 head 标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51808054/