DEMO
使用 typescript
环境准备
- 安装 nodejs、yarn
- 执行
yarn global add vue-cli@3.0.0-beta.6
- 执行
vue create typescript-in-vue
,从此处开始,可以全部选择默认选项完成创建 - 执行
yarn add -D @vue/cli-plugin-typescript
- 执行
yarn add -D typescript@2.7.1
- 执行
vue invoke typescript
- 执行
yarn add vue-class-component
- 执行
yarn add vue-property-decorator
代码修改
- 应用根目录创建 tsconfig.json
- 添加如下代码:
{
"compilerOptions": {
"target": "es5",
"strict": true,
"module": "es2015",
"moduleResolution": "node",
"experimentalDecorators": true,
"lib": [
"es2016",
"dom"
]
}
}
常见问题
- error: Parsing error: Unexpected character ‘@’
- 执行
yarn add -D @vue/eslint-config-typescript
- 修改 package.json 中的
eslintConfig
配置,如下所示
{
"eslintConfig": {
"root": true,
"extends": [
"@vue/typescript",
"plugin:vue/essential",
"eslint:recommended"
]
}
}
- error: ‘Component’ is defined but never used (no-unused-vars)
修改 package.json 中的
eslintConfig
配置,如下所示
{
"eslintConfig": {
"root": true,
"rules": {
"no-unused-vars": "off"
},
"extends": [
"@vue/typescript",
"plugin:vue/essential",
"eslint:recommended"
]
}
}
- error: ‘xxx’ is not defined (no-undef)
修改 package.json 中的
eslintConfig
配置,如下所示
{
"eslintConfig": {
"root": true,
"rules": {
"no-undef": "off"
},
"extends": [
"@vue/typescript",
"plugin:vue/essential",
"eslint:recommended"
]
}
}
参考资料
使用 scss
环境准备
- 执行
yarn add -D sass-loader
- 执行
yarn add -D node-sass
代码修改
- 对 style 标签设置
lang="scss"