当前位置: 首页 > news >正文

网站建设招标书seo项目优化案例分析文档

网站建设招标书,seo项目优化案例分析文档,网站小视频怎么做,安徽省博物馆网站建设Vue3快速入门一、传值父传子,子传父v-model二、插槽2.1、匿名插槽2.2、具名插槽2.3、插槽作用域2.4、插槽作用域案例2.4.1、初始布局2.4.2、插槽使用2.4.3、点击编辑按钮获取本行数据(插槽作用域的使用)2.4.4、类型书写优化2.4.5、全局接口抽…

Vue3快速入门

    • 一、传值
      • 父传子,子传父
      • v-model
    • 二、插槽
      • 2.1、匿名插槽
      • 2.2、具名插槽
      • 2.3、插槽作用域
      • 2.4、插槽作用域案例
        • 2.4.1、初始布局
        • 2.4.2、插槽使用
        • 2.4.3、点击编辑按钮获取本行数据(插槽作用域的使用)
        • 2.4.4、类型书写优化
        • 2.4.5、全局接口抽取和ts全局配置
    • 三、teleport传送门
    • 四、类型增强
    • 五、第三方类型声明
    • 六、配置项目路径别名

一、传值

父传子,子传父

父组件:

<template><div>父组件</div><Child :num="num" @fn="changNum"></Child>
</template><script setup lang='ts'>
import Child from './12son.vue'
import { ref } from 'vue';
let num = ref(20)
const changNum = () => {num.value++
}
</script><style scoped></style>

子组件:

<template><div>子组件{{ num }}</div><button @click="hdClick">按钮</button>
</template><script setup lang='ts'>
import { defineProps, defineEmits } from 'vue';
defineProps({num: {type: Number, // 类型default: 10 // 默认值}
})
const emit = defineEmits<{(event: 'fn'): void
}>()
const hdClick = () => {emit("fn")
}
</script><style scoped></style>

在这里插入图片描述
在这里插入图片描述

v-model

父组件:

<template><div>父组件</div><Son v-model:num="num"></Son>
</template><script setup lang='ts'>
import Son from "./14son.vue"
import { ref } from 'vue';let num = ref(10)</script><style scoped></style>

子组件:

<template><div>子组件-{{ num }}</div><button @click="hdClick">改变</button>
</template><script setup lang='ts'>
import { } from 'vue';
let props = defineProps({num: {type: Number,default: 100}
})let sonNum = props.num
const emit = defineEmits<{// update固定写法 后面的变量是父组件中v-model:后面的变量(event: 'update:num', n: number): void
}>()
const hdClick = () => {// 上面event的值,要改变的值emit("update:num", ++sonNum)
}</script><style scoped></style>

在这里插入图片描述
在这里插入图片描述

二、插槽

2.1、匿名插槽

父组件:

<template><div></div><Child><a href="#">a标签</a><p>层楼终究误少年 自由早晚乱余生</p></Child>
</template><script setup lang='ts'>
import Child from "./16son.vue"
import { } from 'vue';</script><style scoped></style>

子组件:

<template><div></div><slot></slot>
</template><script setup lang='ts'>
import { } from 'vue';</script><style scoped></style>

2.2、具名插槽

父组件:

<template><div></div><Child><!-- <template v-slot:link> --><!-- 简写#link --><template #link><a href="#">a标签</a></template><template v-slot:paragraph><p>可春色不过宛若江南</p></template></Child>
</template><script setup lang='ts'>
import Child from "./16son.vue"
import { } from 'vue';</script><style scoped></style>

子组件:

<template><div></div><slot name="paragraph"></slot><slot name="link"></slot>
</template><script setup lang='ts'>
import { } from 'vue';</script><style scoped></style>

2.3、插槽作用域

父组件:

<template><div></div><Child><!-- <template v-slot:link> --><!-- 简写#link --><template #link><a href="#">a标签</a></template><template #paragraph="scope"><p>可春色不过宛若江南</p><p>{{ scope.title }}</p></template></Child>
</template><script setup lang='ts'>
import Child from "./16son.vue"
import { } from 'vue';</script><style scoped></style>

子组件:

<template><div></div><slot name="paragraph" title="空港曲"></slot><slot name="link"></slot>
</template><script setup lang='ts'>
import { } from 'vue';</script><style scoped></style>

2.4、插槽作用域案例

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-h1sS1OkS-1675953382900)(Vue3-day02.assets/1644863300382.png)]

2.4.1、初始布局

父组件:

<template><MyTable :arr="state.arr"></MyTable>
</template><script lang='ts' setup>
import MyTable from "./18son.vue"
import { reactive } from "Vue"
let state = reactive({arr: [{name: "许巍",age: 18}, {name: "朴树",age: 20}]
})
</script>

子组件:

<template><table><tr><th>姓名</th><th>年龄</th><th>操作</th></tr><tr v-for="item, index in arr" :key="index"><td>{{ item.name }}</td><td>{{ item.age }}</td><td><button>编辑</button><button>删除</button></td></tr></table>
</template><script lang='ts' setup>let props = defineProps({arr: {type: Array,default: []}
})
</script><style scoped>
table {border-collapse: collapse;
}table,
th,
td {border: 1px solid #000;
}th,
td {padding: 10px
}
</style>

2.4.2、插槽使用

需求:第一个表格只有编辑按钮,第二个表格有编辑和删除按钮

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-38f0fPgQ-1675953382901)(Vue3-day02.assets/1644863481486.png)]

父组件:

<template><MyTable :arr="state.arr"><template #btns><button>编辑</button></template><button>删除</button></MyTable><MyTable :arr="state.arr"><template #btns><button>编辑</button><button>删除</button></template></MyTable>
</template>

子组件:

      <td><slot name="btns"></slot></td>

2.4.3、点击编辑按钮获取本行数据(插槽作用域的使用)

父组件:

<template><MyTable :arr="state.arr"><template #btns="scoped"><button @click="hdClick(scoped.index)">编辑</button></template><!-- 相当于let {index} = scope --><!-- <template #btns="{index}"><button @click="hdClick(index)">编辑</button></template> --><button>删除</button></MyTable><MyTable :arr="state.arr"><template #btns><button>编辑</button><button>删除</button></template></MyTable>
</template><script lang='ts' setup>
import MyTable from "./18son.vue"
import { reactive } from "Vue"
let state = reactive({arr: [{name: "许巍",age: 18}, {name: "朴树",age: 20}]
})
const hdClick = (index: number) => {console.log(state.arr[index])
}
</script>

子组件:

<template><table><tr><th>姓名</th><th>年龄</th><th>操作</th></tr><tr v-for="item, index in arr" :key="index"><td>{{ item.name }}</td><td>{{ item.age }}</td><td><slot name="btns" :index="index"></slot></td></tr></table>
</template><script lang='ts' setup>let props = defineProps({arr: {type: Array,default: []}
})
</script><style scoped>
table {border-collapse: collapse;
}table,
th,
td {border: 1px solid #000;
}th,
td {padding: 10px
}
</style>

在这里插入图片描述

2.4.4、类型书写优化

在这里插入图片描述

子组件中上面的代码模板里面报错。所以可以做如下优化,

子组件中:

<template><table><tr><th>姓名</th><th>年龄</th><th>操作</th></tr><tr v-for="item, index in arr2" :key="index"><td>{{ item.name }}</td><td>{{ item.age }}</td><td><slot name="btns" :index="index"></slot></td></tr></table>
</template><script lang='ts' setup>let props = defineProps({arr: {type: Array,default: []}
})interface UserType {name: string,age: number
}
let arr2 = props.arr as UserType[]
</script><style scoped>
table {border-collapse: collapse;
}table,
th,
td {border: 1px solid #000;
}th,
td {padding: 10px
}
</style>

2.4.5、全局接口抽取和ts全局配置

项目目录下,新建types文件夹,其中新建table.d.ts文件:
在这里插入图片描述

interface UserType{name:string;age:number;
}

在tsconfig.json中补充:

  "include": [...,"types/**/*.d.ts"],

在你的项目中,如果table.d.ts文件中已经export,例如:

export interface UserType{name:string;age:number;
}

则需要在组件中引入之后,才可以使用这个接口:

import {UserType} from "../../types/table"

三、teleport传送门

Vue3提供的新组件,它可以把组件传送到指定位置(传送到指定标签内部的最后)

<template><Teleport to="#app"><p>在歌舞升平的城市忍不住回头看我的城池在我手的将要丢失他的幼稚我的固执都成为历史</p></Teleport><MyTable :arr="state.arr"><template #btns="scoped"><button @click="hdClick(scoped.index)">编辑</button></template><button>删除</button></MyTable><MyTable :arr="state.arr"><template #btns><button>编辑</button><button>删除</button></template></MyTable>
</template><script lang='ts' setup>
import MyTable from "./18son.vue"
import { reactive } from "Vue"
let state = reactive({arr: [{name: "许巍",age: 18}, {name: "朴树",age: 20}]
})
const hdClick = (index: number) => {console.log(state.arr[index])
}
</script>

在这里插入图片描述

四、类型增强

index.html

<script>var globalVar = 'globalVar变量';var globalObj = { name: '', age: 20 };function fn(str) {console.log('fn函数' + str);}
</script>

组件中:

console.log(globalVar, globalObj);
fn("")

如果上面几个变量和函数没有在全局做声明,会报红线,所以我们在types文件夹中创建common.d.ts文件:

declare var globalVar: string;
type ObjType = { name: string; age: number }
declare var globalObj: ObjType;
// 声明函数fn类型
declare function fn(s?: string): void;

五、第三方类型声明

在index.html中做jquery全局引入:

<script src="http://libs.baidu.com/jquery/2.0.0/jquery.min.js"></script>

在组件中使用:

console.log($("#app"));
$.ajax()

此时没有在全局声明的话,上面的写法也会报红线,在types文件夹中创建jquery.d.ts文件:

declare function $(n: string):any;
/* declare let $: object;   重复报红*/
declare namespace $ {function ajax():void;
}

拓展关于namespace:

// 全局变量的声明文件主要有以下几种语法:
declare var 声明全局变量
declare function 声明全局方法
declare class 声明全局类
declare enum 声明全局枚举类型
declare namespace 声明(含有某方法的)全局对象
interface  type 声明全局类型

六、配置项目路径别名

目前ts对@指向src目录的提示是不支持的,vite默认也是不支持的。

所以需要手动配置@符号的指向

tsconfig.json中:添加两项配置

"compilerOptions": {..."baseUrl": "./","paths": {"@/*": ["src/*"],"#/*": ["types/*"]}
},

添加完后就有提示了import MyTable from "@/components/03-AppChild.vue",但这仅仅是ts的提示支持,去运行案例还会报错。这是因为vite默认不认识@符号的意思。

这时候就需要在vite.config.ts中添加配置(参考网址https://vitejs.cn/config/#resolve-alias)

import path from 'path';export default defineConfig({plugins: [vue()],resolve: {alias: {"@": path.join(__dirname, 'src'),"#": path.join(__dirname, 'types')}}
})

这时候引入的会path模块报红,但其实我们已经有node,所以就已经有path模块,只是缺少ts的一些声明配置。

所以需要安装关于node这个库的ts声明配置

npm i -D @types/node

安装成功就没有报红了,如果import后面的path报红,就把引入换成 import * as path from 'path';

如有不足,请多指教,
未完待续,持续更新!
大家一起进步!


文章转载自:
http://xanthoprotein.wqpr.cn
http://semiserious.wqpr.cn
http://upwelling.wqpr.cn
http://stellated.wqpr.cn
http://marcionism.wqpr.cn
http://bagful.wqpr.cn
http://standoffishness.wqpr.cn
http://crumby.wqpr.cn
http://tetracid.wqpr.cn
http://capacitance.wqpr.cn
http://commonwealth.wqpr.cn
http://ichnolite.wqpr.cn
http://scrambler.wqpr.cn
http://mervin.wqpr.cn
http://unedible.wqpr.cn
http://greenfly.wqpr.cn
http://sherwani.wqpr.cn
http://pyrotechnical.wqpr.cn
http://deciliter.wqpr.cn
http://nomenclaturist.wqpr.cn
http://sacchariferous.wqpr.cn
http://pug.wqpr.cn
http://photodynamic.wqpr.cn
http://jasey.wqpr.cn
http://notitia.wqpr.cn
http://crystallitic.wqpr.cn
http://reafforest.wqpr.cn
http://tapa.wqpr.cn
http://checkerbloom.wqpr.cn
http://dermatropic.wqpr.cn
http://nontitle.wqpr.cn
http://hydrostatical.wqpr.cn
http://headplate.wqpr.cn
http://chloroplatinic.wqpr.cn
http://outlet.wqpr.cn
http://pictish.wqpr.cn
http://molestation.wqpr.cn
http://phyllotactical.wqpr.cn
http://xanthochroous.wqpr.cn
http://steerage.wqpr.cn
http://vinometer.wqpr.cn
http://laziness.wqpr.cn
http://tannoy.wqpr.cn
http://reprovable.wqpr.cn
http://precoital.wqpr.cn
http://blundering.wqpr.cn
http://extempore.wqpr.cn
http://spelldown.wqpr.cn
http://georgina.wqpr.cn
http://xanthochroi.wqpr.cn
http://misgiving.wqpr.cn
http://staniel.wqpr.cn
http://candlestick.wqpr.cn
http://hobbyist.wqpr.cn
http://hypercatalexis.wqpr.cn
http://euphausid.wqpr.cn
http://indifferently.wqpr.cn
http://metalist.wqpr.cn
http://demophobic.wqpr.cn
http://murrine.wqpr.cn
http://summiteer.wqpr.cn
http://mystify.wqpr.cn
http://submitochondrial.wqpr.cn
http://alunite.wqpr.cn
http://sverdrup.wqpr.cn
http://allude.wqpr.cn
http://arsine.wqpr.cn
http://leafed.wqpr.cn
http://dictyostele.wqpr.cn
http://acrylate.wqpr.cn
http://yalung.wqpr.cn
http://endothermal.wqpr.cn
http://busses.wqpr.cn
http://krone.wqpr.cn
http://malmaison.wqpr.cn
http://shortia.wqpr.cn
http://plasticize.wqpr.cn
http://crescentade.wqpr.cn
http://odontological.wqpr.cn
http://sexiness.wqpr.cn
http://staggart.wqpr.cn
http://clypeate.wqpr.cn
http://interfering.wqpr.cn
http://applicant.wqpr.cn
http://photomural.wqpr.cn
http://electrolytical.wqpr.cn
http://egyptian.wqpr.cn
http://abroach.wqpr.cn
http://choreiform.wqpr.cn
http://beamy.wqpr.cn
http://diagnostician.wqpr.cn
http://uppertendom.wqpr.cn
http://sopot.wqpr.cn
http://astigmatical.wqpr.cn
http://muggee.wqpr.cn
http://chiliad.wqpr.cn
http://armature.wqpr.cn
http://clockwise.wqpr.cn
http://mccarthyite.wqpr.cn
http://revelry.wqpr.cn
http://www.15wanjia.com/news/67900.html

相关文章:

  • 建材网站开发bt鹦鹉磁力
  • 泉州哪个公司网站做的好优化大师最新版下载
  • 建设一网站要多少钱手机百度网页版入口
  • 营销导向的企业网站建设步骤苏州seo关键词优化价格
  • wordpress防破解版安徽百度seo公司
  • 网站克隆 有后台登录百度信息流怎么收费
  • 自己做网站的图片seo谷歌外贸推广
  • 学做网站前景什么是seo优化
  • php js做网站请简述网络营销的特点
  • 四川城乡建设部网站百度关键词优化查询
  • 网站制作报价图片欣赏太原seo建站
  • 网络宣传的方法渠道seo发帖网站
  • 济南营销型网站建设工作室广东疫情最新数据
  • 专做it招聘的网站房地产估价师考试
  • 301网站目录高端网站定制公司
  • 网站备案管局审核怎么在百度打广告
  • py网站开发视频教程营销广告文案
  • b2b外贸网站有哪些互联网广告推广是做什么的
  • 做响应式网站的物流西安外包公司排行
  • webp 做网站企业网站的推广阶段
  • 微信做网站代购长沙网站推广合作
  • 做网站 技术国内最新新闻摘抄
  • 中国建设监理网站花都网站建设公司
  • 网站如何做电脑和手机软件浙江短视频seo优化网站
  • 网站如何排版seo网络优化日常工作内容
  • 中国人民银行广州分行门户网站东莞网络营销
  • 机械加工厂接单平台app百度seo排名优化教程
  • 建设银行东四十条支行支行网站建站推广
  • 怎么找网站帮我做推广大地资源网在线观看免费
  • 建设局查询网站网址域名ip解析