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

Can I define returned jsx in methods property in SFC? #221

Open
wqcstrong opened this issue May 24, 2021 · 3 comments
Open

Can I define returned jsx in methods property in SFC? #221

wqcstrong opened this issue May 24, 2021 · 3 comments

Comments

@wqcstrong
Copy link

wqcstrong commented May 24, 2021

Env

  • "vue": "^2.6.0",
  • "vue-template-compiler": "^2.6.12",
  • "rollup": "^2.48.0",
  • "rollup-plugin-vue": "^5.0.0",
  • "@babel/preset-env": "^7.0.0",
  • "@vue/babel-helper-vue-jsx-merge-props": "^1.2.1",
  • "@vue/babel-preset-jsx": "^1.2.4"

What happened

Following is my code,

//  MyButton.vue

<template>
    <p>Segment: {{ segment() }}</p>
</template>

<script>
export default {
  name: 'MyButton',
  methods: {
    segment() {
      return <b>A segment</b>;
    }
  }
};
</script>

build output as es-module. Last, I got error when using it, the error:

image

Help me, plz~

@wqcstrong
Copy link
Author

the vite plugin process vue is [email protected]

@wqcstrong
Copy link
Author

wqcstrong commented May 24, 2021

That's OK if drop the template block and use render function property:

<script>
export default {
  methods: {
    segment () {
      return <b>A segment</b>
    }
  },
  render () {
    return (
      <p>Segment: { this.segment() }</p>
    )
  }
}
</script>

But I must support the template jsx...

@wqcstrong
Copy link
Author

@sodatea Sorry to bother you, take a look at my issue plz, THX!

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

1 participant