我在试着利用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)您可能需要一个适当的加载程序来处理此文件类型。
我正在使用VueJ与WebPack一起从一个Laravel和Laravel基础安装。我该怎么解决这个问题?
发布于 2019-04-05 16:35:54
当我开始使用Vue和TypeScript时,我一开始遇到了类似的问题,我花了很长时间才开始工作。尝试将其添加到webpack.config.js中
...
module: {
rules: [
{
test: /\.tsx?$/,
use: [{
loader: 'ts-loader',
options: {
appendTsSuffixTo: [ /\.vue$/ ]
}
}],
exclude: /node_modules/
},
// make sure vue-loader comes after ts-loader
{
test: /\.vue$/,
loader: 'vue-loader'
},
...发布于 2019-04-19 20:42:13
试着翻转Connum建议答案的顺序。
module: {
rules: [
{
test: /\.vue$/,
use: 'vue-loader',
},
{
test: /\.ts$/,
exclude: /node_modules/,
use: [{ loader: 'ts-loader', options: { appendTsSuffixTo: [/\.vue$/] } }],
},
]
}为我工作过。你已经安装了虚拟装载机?
npm i -D ts-loader typescript vue-loaderhttps://stackoverflow.com/questions/55539548
复制相似问题