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

现在新增删除传过去的数据 如何能做成响应式的 #9

Open
WEBxiyao opened this issue Jul 8, 2022 · 8 comments
Open

Comments

@WEBxiyao
Copy link

WEBxiyao commented Jul 8, 2022

现在传过去的数据列表想新增一条数据或者删除一条数据 都不能响应式的去更新,只能重新渲染这个组件才能更新,应为setup只走了一次

@superermiao
Copy link

我也是遇到这个问题

@agm1984
Copy link

agm1984 commented Dec 16, 2022

I also encountered this. To solve it, I implemented this custom condition:

const isResettingColumns = ref(false);

const handleResetColumns = async () => {
    /**
     * isResettingColumns is a DOM hack to get the Draggable container
     * to reset the value of the v-model. The draggable list does
     * not reset properly without this combination of isResettingColumns
     * and waiting until nextTick.
     */
    isResettingColumns.value = true;
    localColumns.value = cloneDeep(props.defaultColumns);
    await nextTick();
    isResettingColumns.value = false;
};

...

<Draggable v-if="!isResettingColumns" v-model="localColumns" transition="100">

This momentarily de-renders the draggable container and re-renders it with different state.

@wwwossai
Copy link

@agm1984 thanks, it works. Here's my sample codes:

<template>
  <draggable v-model="imageList" v-if="imageList.length > 0 && visible">
    <template v-slot:item="{ item }">
      <el-image :src="item" />
    </template>
  </draggable>
</template>

<script>
import Draggable from 'vue3-draggable'
export default {
  components: { Draggable },
  data () {
    return {
      visible: true,
      imageList: []
    }
  },
  methods: {
    async addImage (file) {
      this.imageList.push(...get image link from somewhere...)
      this.visible = false
      this.$nextTick(() => {
        this.visible = true
      })
    }
  }
}
</script>

@keygun-development
Copy link

keygun-development commented Jan 10, 2023

@agm1984 You should create a pr for this implementation this helped me out after struggling with the package for a while

@k0ndratov
Copy link

@wwwossai Very grateful for the decision. It helped me.

Repository owner deleted a comment from Pappyskull1 Feb 23, 2024
Repository owner deleted a comment from Pappyskull1 Feb 23, 2024
Repository owner deleted a comment from akashakki Mar 1, 2024
@pedoc
Copy link

pedoc commented Mar 1, 2024

Why ping me?

I've been getting some harassment notifications lately, it's very annoying.

@wottpal
Copy link

wottpal commented Mar 2, 2024

Why ping me?

I've been getting some harassment notifications lately, it's very annoying.

Just report all of them and send the comment's link in the form as a proof. Got 20+ profiles be taken down in the last month.

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

8 participants