vue專案新增ts後問題
阿新 • • 發佈:2021-01-20
技術標籤:VueTypeScript前端開發vuetypescript
1、js-cookie
引入的 Cookie
找不到 module
問題
yarn add @type/js-cookie
yarn add js-cookie
2、使用Ele-UI庫的方法
ts 型別報錯 any
this.$refs.form.resetFields()
this.$refs.form.validate()
解決方法:
const ref: any = this.$refs.form;
ref.resetFields() // 清空表單
ref.validate() // 表單驗證
3、form表單等物件的宣告
private form: any = {
name: '',
code: ''
}
this.form.name
ts報錯 獲取不到
解決方法:
定義
interface
介面引數
須寫在@Component
前
interface formDTO {
name: string,
creditCode: string,
radio: number,
notifyUrl: string,
publicKey: string
}
private form: formDTO = {
name: '',
creditCode: '',
radio: 1,
notifyUrl: '',
publicKey: ''
};