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

when using mixins in component, the mixin's data will overwrite component's data; 数据对象在合并时,以mixins优先,而不是以组件数据优先 #1187

Closed
zhuxindaba opened this issue May 15, 2020 · 5 comments

Comments

@zhuxindaba
Copy link

Version

3.0.0-beta.10

Reproduction link

https://codepen.io/zhuxin/pen/yLYxKpv

Steps to reproduce

      data() {
        return {
          a: 1
        }
      }
    }
    const Comp = {
      mixins: [mixinA],
      data() {
        return {
          a: 3
        }
      },
      render(this: any) {
        return `${this.a}`
      }
    }
    expect(renderToString(h(Comp))).toBe(`3`);

What is expected?

3

What is actually happening?

1


      data() {
        return {
          a: 1
        }
      }
    }
    const Comp = {
      mixins: [mixinA],
      data() {
        return {
          a: 3
        }
      },
      render(this: any) {
        return `${this.a}`
      }
    }
    expect(renderToString(h(Comp))).toBe(`3`);
@Kagashino
Copy link

Could you please spent some time to read the Document first?

@zhuxindaba
Copy link
Author

Could you please spent some time to read the Document first?

I read the document again, but vue3 is actually different from vue2. Is a breaking change?

@Kagashino
Copy link

Kagashino commented May 15, 2020

Well, I found the relative rfcs, it may help you.

There is no more defaultStrat in 3.0. Users must now always provide their own merge strategy functions instead of reusing built-in strategies(in Vue2.0):

/**
 * Default strategy.
 */
var defaultStrat = function (parentVal, childVal) {
  return childVal === undefined
    ? parentVal
    : childVal
};

@zhuxindaba
Copy link
Author

Well, I found the relative rfcs, it may help you.

There is no more defaultStrat in 3.0. Users must now always provide their own merge strategy functions instead of reusing built-in strategies(in Vue2.0):

/**
 * Default strategy.
 */
var defaultStrat = function (parentVal, childVal) {
  return childVal === undefined
    ? parentVal
    : childVal
};

thx~

@zhuxindaba
Copy link
Author

not a bug

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