最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

vue3中如何使用ts

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

如何使用ts

在創(chuàng)建vue腳手架的時(shí)候吧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";
//導(dǎo)入接口類型
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: "睡覺(jué)", isture: false },
? ? ? ? { id: 3, title: "打游戲", isture: false },
? ? ? ? { id: 4, title: "打代碼", isture: true },
? ? ? ],
? ? });
? ? //定義一個(gè)方法用來(lái)接收輸入框里面?zhèn)鱽?lái)的數(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="請(qǐng)輸入你的任務(wù)名稱,按回車鍵確認(rèn)"
? ? ? v-model="title"
? ? ? @keyup.enter="add"
? ? />
? </div>
</template>
<style scoped>
@import "./header.css";
</style>
<script lang="ts">
import { defineComponent, ref } from "vue";
//導(dǎo)入接口類型
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("請(qǐng)輸入內(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";
//導(dǎo)入接口類型
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" ?>清除已完成任務(wù)</button>
? ? ? </div>
</template>
<style scoped>
/* @import"./footer.css"; */
</style>
<script lang="ts">
import { defineComponent } from 'vue'
export default defineComponent({
? ? setup() {
? ? ? ??
? ? },
})
</script>

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

相關(guān)文章

  • vue-cli3+typescript新建一個(gè)項(xiàng)目的思路分析

    vue-cli3+typescript新建一個(gè)項(xiàng)目的思路分析

    這篇文章主要介紹了vue-cli3+typescript新建一個(gè)項(xiàng)目的思路,本文通過(guò)實(shí)例代碼給大家介紹的非常詳細(xì),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2019-08-08
  • vue?this.$router.go(-1);返回時(shí)如何帶參數(shù)

    vue?this.$router.go(-1);返回時(shí)如何帶參數(shù)

    這篇文章主要介紹了vue?this.$router.go(-1);返回時(shí)如何帶參數(shù)問(wèn)題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2023-12-12
  • Vue中子組件不能修改父組件傳來(lái)的Prop值的原因分析

    Vue中子組件不能修改父組件傳來(lái)的Prop值的原因分析

    在Vue中,父子組件之間通過(guò)Prop和Event實(shí)現(xiàn)了數(shù)據(jù)的雙向綁定,但是,Vue設(shè)計(jì)者為什么不允許子組件修改父組件傳遞的Prop呢,本文就來(lái)帶大家探究為什么子組件不能修改Prop,需要的朋友可以參考下
    2023-06-06
  • windows下vue.js開(kāi)發(fā)環(huán)境搭建教程

    windows下vue.js開(kāi)發(fā)環(huán)境搭建教程

    這篇文章主要為大家詳細(xì)介紹了windows下vue.js開(kāi)發(fā)環(huán)境搭建教程,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2017-03-03
  • Vue使用正則校驗(yàn)文本框?yàn)檎麛?shù)

    Vue使用正則校驗(yàn)文本框?yàn)檎麛?shù)

    這篇文章主要介紹了Vue使用正則校驗(yàn)文本框?yàn)檎麛?shù)問(wèn)題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2022-10-10
  • vue?首頁(yè)加載,速度優(yōu)化及解決首頁(yè)白屏的問(wèn)題

    vue?首頁(yè)加載,速度優(yōu)化及解決首頁(yè)白屏的問(wèn)題

    這篇文章主要介紹了vue?首頁(yè)加載,速度優(yōu)化及解決首頁(yè)白屏的問(wèn)題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。
    2022-10-10
  • vue3中?provide?和?inject?用法小結(jié)

    vue3中?provide?和?inject?用法小結(jié)

    父子組件傳遞數(shù)據(jù)時(shí),使用的是props和emit,父?jìng)髯訒r(shí),使用的是?props,如果是父組件傳孫組件時(shí),就需要先傳給子組件,子組件再傳給孫組件,如果多個(gè)子組件或多個(gè)孫組件使用時(shí),就需要傳很多次,會(huì)很麻煩,這篇文章主要介紹了vue3中?provide?和?inject?用法,需要的朋友可以參考下
    2023-11-11
  • vue3.2新增指令v-memo的基本使用教程

    vue3.2新增指令v-memo的基本使用教程

    ue3.2新增了一個(gè)指令v-memo,引入這個(gè)指令的目的是幫助大家更好的為我們的應(yīng)用做性能優(yōu)化,下面這篇文章主要給大家介紹了關(guān)于vue3.2新增指令v-memo基本使用的相關(guān)資料,需要的朋友可以參考下
    2022-09-09
  • vue 授權(quán)獲取微信openId操作

    vue 授權(quán)獲取微信openId操作

    這篇文章主要介紹了vue 授權(quán)獲取微信openId操作,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧
    2020-11-11
  • 基于vue中keep-alive緩存問(wèn)題的解決方法

    基于vue中keep-alive緩存問(wèn)題的解決方法

    今天小編就為大家分享一篇基于vue中keep-alive緩存問(wèn)題的解決方法,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧
    2018-09-09

最新評(píng)論

云南省| 惠州市| 韶关市| 湖北省| 左贡县| 湟中县| 广饶县| 青州市| 本溪市| 大名县| 祥云县| 重庆市| 彭泽县| 望都县| 剑河县| 高安市| 抚顺市| 关岭| 台东市| SHOW| 那曲县| 溧阳市| 鸡泽县| 宝兴县| 微博| 昌都县| 通化县| 临桂县| 平度市| 米脂县| 四会市| 宝山区| 新龙县| 南通市| 修水县| 浠水县| 故城县| 孙吴县| 梁山县| 元江| 松桃|