A while back I created a vue project using vue init webpack .
,
and everything worked fine.
Now I tried to install typescript and ts-loader
. I created a file in src
which contains:
declare module '*.vue' {
import Vue from 'vue'
export default Vue
}
I added tsconfig.json
{
"compilerOptions": {
"target": "es5",
"module": "es2015",
"strict": true,
"moduleResolution": "node",
"allowSyntheticDefaultImports": true,
"sourceMap": true,
},
"include": [
"src/**/*.ts",
"src/**/*.vue"
],
"exclude": [
"node_modules"
]
}
And I renamed the main.js
file to main.ts
and router/index.js
to router/index.ts
.
For the webpack configuration, I added/modified few lines:
{
test: /\.vue$/,
loader: 'vue-loader',
options: {
loaders: {
ts: [
{
loader: 'ts-loader',
options: {
appendTsSuffixTo: [/\.vue$/]
}
}
]
}
}
},
{
test: /\.ts$/,
loader: 'ts-loader'
},
I added for ts-loader
and I modified some stuff for vue-loader (the path for webpack is build/webpack.base.conf.js
)
There are no errors while running npm run dev
but there are few warning though.
The problem here is there is in the file src/components/HelloWorld.vue
<template>
<div class="hello">
<h2>Essential Links</h2>
{{message}}
</div>
</template>
<script lang="ts">
import Vue from 'vue'
export default class AppTest extends Vue {
message: string = 'Hello!'
}
</script>
[Vue warn]: Property or method "message" is not defined on the instance but referenced during render. Make sure that this property is reactive, either in the data option, or for class-based components, by initializing the property
I tried so many ways to fix this by updating the configuration and all but nothing seems to be working.
Can anyone help me out with this?