【发布时间】:2021-04-19 09:54:30
【问题描述】:
我的组件中有以下代码:
computed: {
gridWidth() { return (this.$el && this.$el.offsetWidth) },
gridHeight() { return (this.$el && this.$el.offsetHeight) },
},
mounted(){
console.log(this.$el && this.$el.offsetWidth, this.gridWidth, this.$el && this.$el.offsetHeight, this.gridHeight)
},
控制台输出为:
1766 undefined 931 undefined
为什么计算属性未定义?
以正确的方式成为观察者吗?为什么以及如何实现?
【问题讨论】:
-
你有没有在你的mounted中试过这个......this.$nextTick(() => { console.log(this.$el && this.$el.offsetWidth, this. $el && this.$el.offsetHeight, this.gridHeight)})
标签: vue.js computed-properties