vitejs / vite-plugin-vue2

Vite plugin for Vue 2.7
MIT License
551 stars 47 forks source link

vue component cannot be loaded correctly when data have some specific names #91

Open supergem3000 opened 1 year ago

supergem3000 commented 1 year ago

Describe the bug

when i migrate my project from vue-cli to vite, i meet an unexpected problem! vue component cannot be loaded correctly when data have some specific name code is below:

<template>
  <div>
    <div>EXPORT ISSUES</div>
    <div>{{ showData }}</div>
  </div>
</template>

<script lang="ts">
import { Component, Vue } from 'vue-property-decorator';

@Component({
  name: 'ExportIssues',
})
export default class ExportIssues extends Vue {
  fieldInfo = { default: [] };

  showData = '';
  exportType = 'xlsx';

  get getter() {
    return this.fieldInfo.default;
  }

  created() {
    this.showData = 'loaded correctly';
  }
}
</script>

created method will not run. if delete the line exportType = 'xlsx'; or the getter method, this component will run correctly

I guess its a bug of the compiler. It reads the 'export', 'default' word and do something wrong.

Need your help!


将项目从VueCLI迁移到Vite时遇到了问题。代码如上文。当Vue组件有一个数据叫exportType,一个getter中包含叫default的取值时,这个组件无法正常运行,created方法不执行。把exportType = 'xlsx';那行或者getter删掉就正常了。 猜测是编译器把exportdefault读到了一起,然后编译错了东西? 需要你的帮助!

Reproduction

https://stackblitz.com/edit/vitejs-vite-s1r7wy?file=src%2Fcomponents%2FExportIssues.vue

Steps to reproduce

No response

System Info

System:
    OS: macOS 13.4.1
    CPU: (12) x64 Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz
    Memory: 166.40 MB / 16.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 16.16.0 - ~/.nvm/versions/node/v16.16.0/bin/node
    Yarn: 1.22.19 - ~/.nvm/versions/node/v16.16.0/bin/yarn
    npm: 7.10.0 - ~/.nvm/versions/node/v16.16.0/bin/npm
  Browsers:
    Chrome: 116.0.5845.110
    Safari: 16.5.2
  npmPackages:
    @vitejs/plugin-vue2: ^2.2.0 => 2.2.0 
    vite: 4.4.9 => 4.4.9

Used Package Manager

yarn

Logs

No response

Validations

stackblitz[bot] commented 1 year ago

Fix this issue in StackBlitz Codeflow Start a new pull request in StackBlitz Codeflow.