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

使用jsx动态创建的组件失去双向绑定效果 #261

Open
hand19442 opened this issue Sep 10, 2021 · 1 comment
Open

使用jsx动态创建的组件失去双向绑定效果 #261

hand19442 opened this issue Sep 10, 2021 · 1 comment

Comments

@hand19442
Copy link

代码如下:
onItemClick() { this.$popup({ title: "明细信息详情", showHeader: true, showClose: false, position: "right", headerAlign: "start", showBack: true, content: <SrmForm style="padding: 0 15px;" customizeType="detail" formRefresh={this.formRefresh} columns={this.getColumns()} dataSet={this.dataSet}/>, }); },
环境:
"@babel/plugin-proposal-class-properties": "^7.13.0", "@babel/plugin-syntax-dynamic-import": "^7.8.3", "@babel/plugin-syntax-jsx": "^7.12.13", "@babel/plugin-transform-classes": "^7.13.0", "@babel/plugin-transform-runtime": "^7.13.15", "@babel/preset-env": "^7.13.15", "@vue/babel-helper-vue-jsx-merge-props": "^1.2.1", "@vue/babel-preset-jsx": "^1.2.4",
在点击事件方法里面动态创建了一个弹窗,content参数是弹窗的默认插槽,SrmForm组件接收formRefresh参数(布尔值)并实例化后,外层改变this.formRefresh的值SrmForm组件无法感知,但是修改this.dataSet(对象)是可以的。有什么好的解决办法吗?

@haha4445
Copy link

haha4445 commented Jul 1, 2024

不清楚你用的UI库,但是今天使用ant-design-vue遇到这个问题,解决方法是调用modal或者你这个popup本身的update方法,这个视图问题不是这个jsx解析导致的。例如以下为antdv库示例代码

<template>
  <a-button @click="countDown">
    Open modal to close in 5s
  </a-button>
</template>
<script>
export default {
  methods: {
    countDown() {
      let secondsToGo = 5;
      const modal = this.$success({
        title: 'This is a notification message',
        content: `This modal will be destroyed after ${secondsToGo} second.`,
      });
      const interval = setInterval(() => {
        secondsToGo -= 1;
        modal.update({
          content: `This modal will be destroyed after ${secondsToGo} second.`,
        });
      }, 1000);
      setTimeout(() => {
        clearInterval(interval);
        modal.destroy();
      }, secondsToGo * 1000);
    },
  },
};
</script>

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