網(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放在項(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
相關(guān)推薦
- 2022-06-01 python?嵌套型partials的使用_python
- 2021-12-11 Redis之sql緩存的具體使用_Redis
- 2022-08-19 淺談tensorflow與pytorch的相互轉(zhuǎn)換_python
- 2022-05-08 一篇文章詳細(xì)解釋C++的友元(friend)_C 語言
- 2022-10-05 python?slack桌面自動化開發(fā)工具_(dá)python
- 2022-03-22 C語言圍圈報數(shù)題目代碼實(shí)現(xiàn)_C 語言
- 2022-11-08 Golang連接并操作PostgreSQL數(shù)據(jù)庫基本操作_Golang
- 2022-04-27 簡單聊聊PyTorch里面的torch.nn.Parameter()_python
- 最近更新
-
- window11 系統(tǒng)安裝 yarn
- 超詳細(xì)win安裝深度學(xué)習(xí)環(huán)境2025年最新版(
- Linux 中運(yùn)行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎(chǔ)操作-- 運(yùn)算符,流程控制 Flo
- 1. Int 和Integer 的區(qū)別,Jav
- spring @retryable不生效的一種
- Spring Security之認(rèn)證信息的處理
- Spring Security之認(rèn)證過濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權(quán)
- redisson分布式鎖中waittime的設(shè)
- maven:解決release錯誤:Artif
- restTemplate使用總結(jié)
- Spring Security之安全異常處理
- MybatisPlus優(yōu)雅實(shí)現(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被代理目標(biāo)對象命令
- Spring中的單例模式應(yīng)用詳解
- 聊聊消息隊(duì)列,發(fā)送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠(yuǎn)程分支