typescript - 组件装饰器的 vue-loader 解析错误

标签 typescript webpack vue.js

我在使用 vue、typescript、webpack 和组件装饰器时遇到问题。

这里是错误

ERROR in ./app/modules/popin-ratings-reviews/templates/HelloWorld.vue?vue&type=script&lang=ts (./node_modules/vue-loader/lib??vue-loader-options!./app/modules/popin-ratings-reviews/templates/HelloWorld.vue?vue&type=script&lang=ts) 10:0 Module parse failed: Unexpected character '@' (10:0) You may need an appropriate loader to handle this file type. | import { Component, Prop, Vue } from 'vue-property-decorator'; | @Component | export default class HelloWorld extends Vue { | message = 'hello world'; @ ./app/modules/popin-ratings-reviews/templates/HelloWorld.vue?vue&type=script&lang=ts 1:0-130 1:146-149 1:151-278 1:151-278 @ ./app/modules/popin-ratings-reviews/templates/HelloWorld.vue @ ./app/modules/popin-ratings-reviews/index.m.ts

webpack vue-loader 好像无法解析组件装饰器语法。 我该如何解决?

最佳答案

我找到了解决方案

这是我使用的 webpack 规则的配置,它正在运行

rules: [
  {
    test: /\.tsx?$/,
    exclude: [
      /node_modules/
    ],
    use: {
      loader: "ts-loader",
      options: {
        appendTsSuffixTo: [/\.vue$/]
      }
    }
  },
  {
    test: /\.vue$/,
    use: {
      loader: "vue-loader"
    }
  }
  ...

关于typescript - 组件装饰器的 vue-loader 解析错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50911751/

相关文章:

javascript - 如何接受 webpack 的 api 访问?

jquery - 当Jquery更改文本输入时,Vuejs如何强制v-model更新?

javascript - Vue/Nuxt.js - 计算嵌套 JSON 值的总值

generics - 我可以使用 function.call() 调用通用函数吗?

reactjs - 如何修复 "SyntaxError: Cannot use import statement outside a module"

reactjs - typescript 错误: Property 'code' does not exist on type 'KeyboardEvent<HTMLInputElement>'

vue.js - 视觉 : How do you add E2E tests after not including them in initial webpack template?

vue.js - vue + chosen-js : can not import css of chosen-js with chosen-sprite. png

javascript - Vueify + Elixir + 热加载 - 未捕获的类型错误 : Cannot read property 'indexOf' of undefined

typescript - 使用自己的属性推断类型