Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

can`t get this in props default function #1886

Closed
xxholly32 opened this issue Aug 18, 2020 · 6 comments
Closed

can`t get this in props default function #1886

xxholly32 opened this issue Aug 18, 2020 · 6 comments

Comments

@xxholly32
Copy link

xxholly32 commented Aug 18, 2020

Version

3.0.0-rc.5

Reproduction link

https://jsfiddle.net/xxholly32/w7k8vzng/19/

Steps to reproduce

https://jsfiddle.net/xxholly32/w7k8vzng/19/

i have two related props theme and contentHtml, but i cant get information from default function.

What is expected?

like vue2 , i can get theme value in default function

What is actually happening?

console will be 'undefined'


i think props default function should have attr like setup , or this should be work again

@xxholly32 xxholly32 changed the title cant get this` in props default function can`t get this in props default function Aug 18, 2020
@yyx990803
Copy link
Member

With the commit above you should be able to do

contentHtml: {
      type: String,
      default (props) {
        console.log(props.theme)
      },
    }

I think it's best to prohibit this usage inside prop default functions and validators. This is technically a breaking change and we will need an RFC/migration guide item for it.

@xxholly32
Copy link
Author

nice

I see this problem still cant work in your way the current version 3.0.0-rc.5

https://jsfiddle.net/xxholly32/w7k8vzng/21/

@skirtles-code
Copy link
Contributor

@yyx990803 In Vue 2, accessing this allowed access to injections, properties from Vue.prototype and the store. Any one of these could have been used to provide a default based on configuration/locale/theme.

In particular, the documentation includes the following example for provide/inject:

const Child = {
  inject: ['foo'],
  props: {
    bar: {
      default () {
        return this.foo
      }
    }
  }
}

I don't know how often this was used. Here's an example I found in the Vuetify codebase that passes global configuration to a default function:

https://github.com/vuetifyjs/vuetify/blob/5533b030a3f892abed057dbb00946d57352e6751/packages/vuetify/src/mixins/mobile/index.ts#L16

@beetaa
Copy link

beetaa commented Aug 23, 2020

nice

I see this problem still cant work in your way the current version 3.0.0-rc.5

jsfiddle.net/xxholly32/w7k8vzng/21

rc.7 is OK.

@xxholly32
Copy link
Author

Use inject to set props default value was possibile. did you have any solution now ? @skirtles-code

@skirtles-code
Copy link
Contributor

@xxholly32 Not directly. You could use a computed property to apply a default instead.

@github-actions github-actions bot locked and limited conversation to collaborators Nov 5, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants