日本免费高清视频-国产福利视频导航-黄色在线播放国产-天天操天天操天天操天天操|www.shdianci.com

學(xué)無先后,達(dá)者為師

網(wǎng)站首頁 編程語言 正文

使用Element Plus <script lang=“ts“ setup> 加上lang=“ts“后編譯錯誤

作者:No Bug 更新時間: 2022-07-02 編程語言

部分代碼:

<template>
  <el-input v-model="input" placeholder="Please input" />
</template>

<script lang="ts" setup>
import { ref } from 'vue'
const input = ref('')
</script>

 瀏覽器報錯:

在這里搞了幾個小時,后面發(fā)現(xiàn)是加了 lang=js 的原因

1.下載typescript和loader

npm install typescript ts-loader --save-dev

2.  配置vue.config.js  添加下面的代碼

configureWebpack: {    
      resolve: { extensions: [".ts", ".tsx", ".js", ".json"] },    
      module: {        
        rules: [    
          {    
            test: /\.tsx?$/,    
            loader: 'ts-loader',    
            exclude: /node_modules/,    
            options: {
              appendTsSuffixTo: [/\.vue$/],    
            }    
          }        
        ]    
      }    
    }

添加好后如下:

const { defineConfig } = require('@vue/cli-service')
module.exports = defineConfig({
  transpileDependencies: true,
  configureWebpack: {
    resolve: { extensions: [".ts", ".tsx", ".js", ".json"] },
    module: {
      rules: [
        {
          test: /\.tsx?$/,
          loader: 'ts-loader',
          exclude: /node_modules/,
          options: {
            appendTsSuffixTo: [/\.vue$/],
          }
        }
      ]
    }
  }
})

 3.  新建tsconfig.json放在項(xiàng)目根目錄

{
    "compilerOptions": {
      "target": "es5",
      "module": "commonjs",
      "strict": true,
      "strictNullChecks": true,
      "esModuleInterop": true,
      "experimentalDecorators": true
    }
}

4.  在src根目錄下新建vue-shim.d.ts   這個文件可以讓vue識別ts文件(不加會報錯)

declare module "*.vue" {
    import Vue from "vue";
    export default Vue;
}  

在第四步出現(xiàn)這個錯誤不影響允許,看錯誤提示是因?yàn)椴环螮SLint規(guī)范,我也不知道怎么改。

但是這看著就很不舒服,可以把ESLint檢測關(guān)閉(按一下步驟操作就行)

 

這就舒服多了 

 

成功展示。


原文鏈接:https://blog.csdn.net/qq_61672548/article/details/125506231

欄目分類
最近更新