欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

vue3中如何使用ts

 更新時間:2022年05月30日 10:27:17   作者:萬事勝意sy  
這篇文章主要介紹了vue3中如何使用ts,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教

如何使用ts

在創(chuàng)建vue腳手架的時候吧typescript選上

app.vue

<template>
? <!-- <div id="nav">
? ? <router-link to="/">Home</router-link> |
? ? <router-link to="/about">About</router-link>
? </div>
? <router-view/> -->
? <div id="root">
? ? <div className="todo-container">
? ? ? <div className="todo-wrap">
? ? ? ? <Header :addtodo="addtodo"/>
? ? ? ? <List :todos="state.todos" />
? ? ? ? <Footer />
? ? ? </div>
? ? </div>
? </div>
</template>
<script lang="ts">
import { defineComponent, reactive } from "vue";
import Footer from "./components/footer/footer.vue";
import Header from "./components/header/header.vue";
import List from "./components/list/list.vue";
//導入接口類型
import {todo} from "./type/todo"
export default defineComponent({
? components: { List, Header, Footer },
? setup() {
? ? const state = reactive({
? ? ? todos: [
? ? ? ? { id: 1, title: "吃飯", isture: true },
? ? ? ? { id: 2, title: "睡覺", isture: false },
? ? ? ? { id: 3, title: "打游戲", isture: false },
? ? ? ? { id: 4, title: "打代碼", isture: true },
? ? ? ],
? ? });
? ? //定義一個方法用來接收輸入框里面?zhèn)鱽淼臄?shù)據(jù)并把它加到state.todos里面面
? ? const addtodo=(todo:todo)=>{
? ? ? state.todos.unshift(todo)
? ? }
? ? return {
? ? ? state,
? ? ? addtodo
? ? };
? },
});
</script>
<style>
@import "./App.css";
</style>

header.vue

<template>
? <div class="todo-header">
? ? <input
? ? ? type="text"
? ? ? placeholder="請輸入你的任務名稱,按回車鍵確認"
? ? ? v-model="title"
? ? ? @keyup.enter="add"
? ? />
? </div>
</template>
<style scoped>
@import "./header.css";
</style>
<script lang="ts">
import { defineComponent, ref } from "vue";
//導入接口類型
import { todo } from "../../type/todo";
export default defineComponent({
? props: {
? ? addtodo: {
? ? ? type: Function,
? ? ? required: true,
? ? },
? },
? setup(props) {
? ? const title = ref("");
? ? const add = () => {
? ? ? if (title.value == "") {
? ? ? ? alert("請輸入內(nèi)容");
? ? ? }
? ? ? const todo: todo = {
? ? ? ? id: Date.now(),
? ? ? ? title: title.value,
? ? ? ? isture: false,
? ? ? };
? ? ? props.addtodo(todo);
? ? ? title.value=''
? ? };
? ? return {
? ? ? add,
? ? ? title,
? ? };
? },
});
</script>

list.vue

<template>
? ? <ul className="todo-main">
? ? ? ? ?<Listitem v-for="(todos,index) in todos" :key="todos.id" :todos='todos'></Listitem>
? ? </ul>
</template>
<style scoped>
@import"./list.css";
</style>
<script lang="ts">
import Listitem from "./listitem/listitem.vue"
import { defineComponent } from 'vue'
export default defineComponent({
? ? components:{
? ? ? ? Listitem
? ? },
? ? props:{
? ? ? ? todos:Object
? ? }
? ? ,
? ? setup() {
? ? ? ??
? ? },
})
</script>

listitem.vue

<template>
?
? ? <li ?class="itli" >
? ? ? <label>
? ? ? ? <input type="checkbox" v-model="todos.isture" />
? ? ? ? <span>{{todos.title}}</span>
? ? ? </label>
? ? ? <button
? ? ? ? class="btn btn-danger"
? ? ? ? ? ? ?>刪除</button>
? ? </li>
?
</template>
<style scoped>
@import "./listitem.css";
</style>
<script lang="ts">
import { defineComponent } from "vue";
//導入接口類型
import {todo} from "../../../type/todo"
export default defineComponent({
? setup() {},
? props:{
//定義todos的類型是自己定義的todo接口
? ? todos:Object as ()=>todo
? }
});
</script>

footer.vue

<template>
? ? <div class="todo-footer">
? ? ? ? <label>
? ? ? ? ? <input type="checkbox" ? ? />
? ? ? ? </label>
? ? ? ? <span ?>
? ? ? ? ? <span >已完 </span> / 全部?
? ? ? ? </span>
? ? ? ? <button class="btn btn-danger" ?>清除已完成任務</button>
? ? ? </div>
</template>
<style scoped>
/* @import"./footer.css"; */
</style>
<script lang="ts">
import { defineComponent } from 'vue'
export default defineComponent({
? ? setup() {
? ? ? ??
? ? },
})
</script>

以上為個人經(jīng)驗,希望能給大家一個參考,也希望大家多多支持腳本之家。

相關文章

  • 使用Vue開發(fā)一個實時性時間轉換指令

    使用Vue開發(fā)一個實時性時間轉換指令

    我們就來實現(xiàn)這樣一個Vue自定義指令v-time,將表達式傳入的時間戳實時轉換為相對時間。下面小編給大家?guī)砹耸褂肰ue開發(fā)一個實時性時間轉換指令,需要的朋友參考下吧
    2018-01-01
  • vue2.x 對象劫持的原理實現(xiàn)

    vue2.x 對象劫持的原理實現(xiàn)

    這篇文章主要介紹了vue2.x 對象劫持的原理實現(xiàn),文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧
    2020-04-04
  • vue2.0與bootstrap3實現(xiàn)列表分頁效果

    vue2.0與bootstrap3實現(xiàn)列表分頁效果

    這篇文章主要為大家詳細介紹了vue2.0與bootstrap3實現(xiàn)列表分頁效果,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2017-11-11
  • Vue的混合繼承詳解

    Vue的混合繼承詳解

    這篇文章主要介紹了Vue的混合繼承,有需要的朋友可以借鑒參考下,希望能夠有所幫助,希望能夠給你帶來幫助
    2021-11-11
  • vue-model實現(xiàn)簡易計算器

    vue-model實現(xiàn)簡易計算器

    這篇文章主要為大家詳細介紹了vue-model實現(xiàn)簡易計算器,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2020-08-08
  • 詳解Vue生命周期的示例

    詳解Vue生命周期的示例

    本篇文章主要介紹了詳解Vue生命周期的示例,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2017-03-03
  • vue+openlayer5獲取當前鼠標滑過的坐標實現(xiàn)方法

    vue+openlayer5獲取當前鼠標滑過的坐標實現(xiàn)方法

    在vue項目中怎么獲取當前鼠標劃過的坐標呢?下面通過本文給大家分享實現(xiàn)步驟,感興趣的朋友跟隨小編一起看看吧
    2021-11-11
  • 分分鐘玩轉Vue.js組件

    分分鐘玩轉Vue.js組件

    這篇文章教大家如何分分鐘玩轉Vue.js組件,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2016-10-10
  • Vue編譯器optimize源碼分析

    Vue編譯器optimize源碼分析

    這篇文章主要為大家介紹了Vue?編譯器optimize源碼分析,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪
    2022-07-07
  • Vue+Element UI+vue-quill-editor富文本編輯器及插入圖片自定義

    Vue+Element UI+vue-quill-editor富文本編輯器及插入圖片自定義

    這篇文章主要為大家詳細介紹了Vue+Element UI+vue-quill-editor富文本編輯器及插入圖片自定義,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2019-08-08

最新評論