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

named slot + forceUpdate dont work #13111

Closed
zhangenming opened this issue Nov 2, 2023 · 2 comments
Closed

named slot + forceUpdate dont work #13111

zhangenming opened this issue Nov 2, 2023 · 2 comments

Comments

@zhangenming
Copy link

zhangenming commented Nov 2, 2023

Version

2.7.15

Reproduction link

codesandbox.io

Steps to reproduce

click button

What is expected?

has reactivity

What is actually happening?

no reactivity
image

@posva
Copy link
Member

posva commented Nov 2, 2023

The proper way to update the array is with $set() or splice() (https://v2.vuejs.org/v2/guide/reactivity.html#For-Arrays).
Note you will see the same issue with <template #default>, this is because with the template you will need to call $forceUpdate() on the child component Swatch as $forceUpdate() doesn't touch children:

<template>
  <div id="app">
    <button @click="f">{{ x }}</button>

    <!-- default slot OK -->
    <Swatches>
      {{ x }}
    </Swatches>

    <!-- named slot BAD -->
    <Swatches ref="sw1">
      <template #qqqqqq>{{ x }} </template>
    </Swatches>
  </div>
</template>

<script>
import Swatches from "./components/Swatches";

export default {
  components: {
    Swatches,
  },
  data: () => ({
    x: [1],
  }),
  methods: {
    async f() {
      // this.$set(this.x, 0, this.x[0] + 1)
      this.x[0]++
      this.$forceUpdate()
      this.$refs.sw1.$forceUpdate()
    },
  },
};
</script>

@posva posva closed this as not planned Won't fix, can't repro, duplicate, stale Nov 2, 2023
@zhangenming
Copy link
Author

I recommend changing the documentation, with the caveat that forceUpdate only works with unnamed slots

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants