【发布时间】:2019-08-27 14:28:23
【问题描述】:
我正在尝试在 Vue SFC 中使用 TypeScript 的优势,
安装ts-loader、typescript依赖项
我添加了 tsconfig.json 配置
// tsconfig.json
{
"compilerOptions": {
// this aligns with Vue's browser support
"target": "es5",
// this enables stricter inference for data properties on `this`
"strict": true,
// if using webpack 2+ or rollup, to leverage tree shaking:
"module": "es2015",
"moduleResolution": "node"
}
}
但是当尝试编译下一个组件时,它显示错误。
<script lang="ts">
import Vue from "vue";
import { mapState,mapGetters } from 'vuex'
export default Vue.extend({
data() {
return {
number : 0
}
},
methods:{
// error void
upCount() : void {
this.$store.commit('increment');
},
downCount() : void{
this.$store.commit('decrement');
},
upCountBy() : void {
this.$store.commit('incrementBy',{count : this.number});
}
},
....
错误
模块解析失败:意外令牌 (45:12) 您可能需要一个 适当的加载器来处理这种文件类型。
我正在使用来自 Laravel 和 Laravel Mix 基础安装的 VueJs 和 WebPack。我该如何解决?
【问题讨论】:
-
示例中的哪一行与错误消息中的第 45 行相对应?
-
@Connum 是的,代码里有注释,返回void类型或者任何return都标记为错误
标签: javascript laravel typescript vue.js