Skip to content

Provide/Inject Works Inconsistently with Templates for Reactive Properties #4196

Closed
@jmcooper

Description

@jmcooper

Version

3.2.0-beta.5

Reproduction link

https://sfc.vuejs.org/#eyJBcHAudnVlIjoiPHRlbXBsYXRlPlxuICA8aDE+PENoaWxkIC8+PC9oMT5cbjwvdGVtcGxhdGU+XG5cbjxzY3JpcHQ+XG5pbXBvcnQgeyBjb21wdXRlZCB9IGZyb20gJ3Z1ZSc7XG5pbXBvcnQgQ2hpbGQgIGZyb20gJy4vY2hpbGQudnVlJ1xuICBcbmV4cG9ydCBkZWZhdWx0IHtcbiAgY29tcG9uZW50czogeyBDaGlsZCB9LFxuICBwcm92aWRlOiB7XG4gICAgdXNlcjogY29tcHV0ZWQoKCkgPT4gJ0ppbScpLFxuICB9LFxufTtcbjwvc2NyaXB0PiIsImNoaWxkLnZ1ZSI6Ijx0ZW1wbGF0ZT5cbiAgPGRpdj5Vc2VyOiB7eyB1c2VyLnZhbHVlIH19PC9kaXY+XG48L3RlbXBsYXRlPlxuXG48c2NyaXB0PlxuZXhwb3J0IGRlZmF1bHQge1xuICBpbmplY3Q6IFsndXNlciddLFxufVxuPC9zY3JpcHQ+In0=

Steps to reproduce

Create a parent component like this one:

<template>...</template>
<script>
import { computed } from 'vue';

export default {
  provide: {
    user: computed(() => 'jim'),
  },
};
</script>

And then create a child component like this one:

<template>
  <div>{{ user.value }}</div>
</template>

<script>
export default {
  inject: ['user'],
}
</script>

What is expected?

I should not need to use .value in the template in order to be consistent with reactivity in the composition API.

What is actually happening?

I am required to use .value when using using computed() to make items reactive with provide/inject, but I don't have to use .value when using computed() with the composition API.


This behavior seems inconsistent. At a minimum, it seems like this inconsistency should receive better treatment in the docs to explain why there's a difference.

Metadata

Metadata

Assignees

No one assigned

    Labels

    has workaroundA workaround has been found to avoid the problemneed guidanceThe approach/solution in the PR is unclear and requires guidance from maintainer to proceed further.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions