A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/vuejs/vue-next/issues/2791 below:

Adding to this.$options.computed during `beforeCreate` only works if `computed` is already defined on component · Issue #2791 · vuejs/core · GitHub

Version

3.0.4

Reproduction link

https://jsfiddle.net/6k3nod2c/

Steps to reproduce

Create a component / app with a mixin that adds to this.$options.computed.

const mixin = {
  beforeCreate() {
    if (!this.$options.computed) {
      this.$options.computed = {};
    }
    
    this.$options.computed.value = () => {
    	return 'works';
    }
  }
}

Vue.createApp({
  mixins: [mixin],
  // computed: {} // Uncommenting this line makes it work
}).mount('#app')
What is expected?

Expect this.value to be "works".

What is actually happening?

this.value is undefined.

In vue 2 this worked.
In vue 3 this only works if the computed option is already defined.

lovetingyuan, SeregPie and valq7711


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4