-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Vue 2 + TypeScript 筆記 #16
Comments
Vue cli 開新專案的時候就會問 要不要安裝 Typescript 了 但如果你是現有的專案要加 Typescript 怎辦? $ vue add typescript 其他優質整合文章: |
接下來就是一連串的問題問你要不要裝某某套件
基本上我都選 Yes,因為還不知道幹嘛用的,都先試試看 |
延續上一篇: class-style component syntax why-i-use-vue-class-component 利弊分析 其他 |
本來以為寫完 嗯 噴了幾個紅紅的 error
這邊是在跟你說 function 參數後面必須定義型別,於是我們給他加上該有的型別。 來到 apis/index.ts line 4 做修改 async login(email: string, password: string) { 解決~ |
接下來是這個
|
然後一切都沒問題之後,打開首頁?靠怎麼是預設的畫面 原來 App.vue <template>
<div id="app">
<img alt="Vue logo" src="./assets/logo.png">
<HelloWorld msg="Welcome to Your Vue.js + TypeScript App"/>
</div>
</template>
<script lang="ts">
import { Component, Vue } from 'vue-property-decorator';
import HelloWorld from './components/HelloWorld.vue';
@Component({
components: {
HelloWorld,
},
})
export default class App extends Vue {}
</script>
<style lang="scss">
#app {
font-family: 'Avenir', Helvetica, Arial, sans-serif;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
text-align: center;
color: #2c3e50;
margin-top: 60px;
}
</style> 改回來 <template>
<div class="wrapper">
<router-view></router-view>
</div>
</template>
<script lang="ts">
import { Vue } from 'vue-property-decorator';
export default class App extends Vue {
name!: string;
}
</script> 這中間有遇到的問題: microsoft/TypeScript-Vue-Starter#36 |
JSX in vue |
錯誤解決方式
因為某種需要使用了 event bus,但在 console 裡面會一直跳上面這個錯誤,搜尋了一下之後發現原來官網文件裡面就有講到,不過看得不是很懂。 後來在 CSDN 找到一篇文章有提供詳細的範例
在 node_modules/element-ui/src/types/form.d.ts 裡面可以找到已經定義好的 types,所以就直接拿來用吧 import { Form } from 'element-ui';
...
(this.$refs[formName] as Form).resetFields(); 同場加映 resetFields() 解法 import { Form } from 'element-ui';
...
(this.$refs[formName] as Form).validate(async (valid) => {
if (valid) {
alert('submit!');
} else {
return false;
}
}); |
不要在 |
vue 2.x Typescript 的整合很差,官網文件幾乎沒有Vue + Typescript目前為止最熱門(完整?)的套件是 Vuex 也是,詳情請見討論串目前為止最熱門(完整?)的套件是 vuex-module-decorators 其他vuex-persist - 將 vuex store 儲存 Localstorage (預設,可變更),使資料不會因為重新整理而消失 |
求大大(TypeScript)手下留情
The text was updated successfully, but these errors were encountered: