vue+typescript+scss开发指南

DEMO

  1. https://github.com/shawnwang5/vue-boilerplate
  2. https://github.com/shawnwang5/vue-boilerplate-for-pc

使用 typescript

环境准备
  1. 安装 nodejs、yarn
  2. 执行 yarn global add vue-cli@3.0.0-beta.6
  3. 执行 vue create typescript-in-vue,从此处开始,可以全部选择默认选项完成创建
  4. 执行 yarn add -D @vue/cli-plugin-typescript
  5. 执行 yarn add -D typescript@2.7.1
  6. 执行 vue invoke typescript
  7. 执行 yarn add vue-class-component
  8. 执行 yarn add vue-property-decorator
代码修改
  1. 应用根目录创建 tsconfig.json
  2. 添加如下代码:
{
      "compilerOptions": {
        "target": "es5",
        "strict": true,
        "module": "es2015",
        "moduleResolution": "node",
        "experimentalDecorators": true,
        "lib": [
          "es2016",
          "dom"
        ]
      }
}
常见问题
  • error: Parsing error: Unexpected character ‘@’
  1. 执行 yarn add -D @vue/eslint-config-typescript
  2. 修改 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"
        ]
    }
}
参考资料
  1. vuex-class
  2. vue-class-component
  3. vue-property-decorator

使用 scss

环境准备
  1. 执行 yarn add -D sass-loader
  2. 执行 yarn add -D node-sass
代码修改
  1. 对 style 标签设置 lang="scss"
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

阿祥_csdn

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值