網(wǎng)站首頁 編程語言 正文
部分代碼:
<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放在項目根目錄
{
"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)這個錯誤不影響允許,看錯誤提示是因為不符合ESLint規(guī)范,我也不知道怎么改。
但是這看著就很不舒服,可以把ESLint檢測關(guān)閉(按一下步驟操作就行)
這就舒服多了
成功展示。
原文鏈接:https://blog.csdn.net/qq_61672548/article/details/125506231
相關(guān)推薦
- 2022-04-25 python中關(guān)于py文件之間相互import的問題及解決方法_python
- 2022-10-16 Python?Celery動態(tài)添加定時任務(wù)生產(chǎn)實踐指南_python
- 2023-02-07 k8s集群部署時etcd容器不停重啟問題以及處理詳解_云和虛擬化
- 2022-09-26 ASP.NET?MVC打印表格并實現(xiàn)部分視圖表格打印_實用技巧
- 2022-02-05 如何解決決策樹可視化的中文亂碼問題?(部分解決)
- 2023-01-21 C++實現(xiàn)逆波蘭表達式的例題詳解_C 語言
- 2022-04-11 一篇文章帶你入門python之推導(dǎo)式_python
- 2024-02-29 UNI-APP開發(fā)之插件安裝失敗,離線安裝
- 最近更新
-
- window11 系統(tǒng)安裝 yarn
- 超詳細win安裝深度學(xué)習環(huán)境2025年最新版(
- Linux 中運行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎(chǔ)操作-- 運算符,流程控制 Flo
- 1. Int 和Integer 的區(qū)別,Jav
- spring @retryable不生效的一種
- Spring Security之認證信息的處理
- Spring Security之認證過濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權(quán)
- redisson分布式鎖中waittime的設(shè)
- maven:解決release錯誤:Artif
- restTemplate使用總結(jié)
- Spring Security之安全異常處理
- MybatisPlus優(yōu)雅實現(xiàn)加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務(wù)發(fā)現(xiàn)-Nac
- Spring Security之基于HttpR
- Redis 底層數(shù)據(jù)結(jié)構(gòu)-簡單動態(tài)字符串(SD
- arthas操作spring被代理目標對象命令
- Spring中的單例模式應(yīng)用詳解
- 聊聊消息隊列,發(fā)送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠程分支