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

想自己做淘宝有什么网站吗如何在百度上推广业务

想自己做淘宝有什么网站吗,如何在百度上推广业务,制造业网站建设,成都哪家做网站最好「写在前面」 本文为尚硅谷禹神 Vue3 教程的学习笔记。本着自己学习、分享他人的态度,分享学习笔记,希望能对大家有所帮助。推荐先按顺序阅读往期内容: 1. Vue3 学习笔记(Day1) 2. Vue3 学习笔记(Day2&…

「写在前面」

本文为尚硅谷禹神 Vue3 教程的学习笔记。本着自己学习、分享他人的态度,分享学习笔记,希望能对大家有所帮助。推荐先按顺序阅读往期内容:
1. Vue3 学习笔记(Day1)
2. Vue3 学习笔记(Day2)
3. Vue3 学习笔记(Day3)
4. Vue3 学习笔记(Day4)


目录

  • 6 组件通信
    • 6.1 props
    • 6.2 自定义事件
    • 6.3 mitt
    • 6.4 v-model
    • 6.5 $attrs
    • 6.6  parent
    • 6.7 provide、inject
    • 6.8 pinia
    • 6.9 slot

6 组件通信

P52:https://www.bilibili.com/video/BV1Za4y1r7KE?p=52

Vue3组件通信和Vue2的区别:

  • 移出事件总线,使用 mitt代替。
  • vuex换成了 pinia
  • .sync优化到了 v-model里面了。
  • $listeners所有的东西,合并到 $attrs中了。
  • $children被砍掉了。

常见搭配形式:

alt

6.1 props

概述:props是使用频率最高的一种通信方式,常用与 :父 ↔ 子

  • 父传子:属性值是 非函数
  • 子传父:属性值是 函数

父组件:

<template>
<div class="father">
<h3>父组件,</h3>
<h4>我的车:{{ car }}</h4>
<h4>儿子给的玩具:{{ toy }}</h4>
<Child :car="car" :getToy="getToy"/>
</div>
</template>

<script setup lang="ts" name="Father">
import Child from './Child.vue'
import { ref } from "vue";
// 数据
const car = ref('奔驰')
const toy = ref()
// 方法
function getToy(value:string){
toy.value = value
}
</script>

子组件

<template>
<div class="child">
<h3>子组件</h3>
<h4>我的玩具:{{ toy }}</h4>
<h4>父给我的车:{{ car }}</h4>
<button @click="getToy(toy)">玩具给父亲</button>
</div>
</template>

<script setup lang="ts" name="Child">
import { ref } from "vue";
const toy = ref('奥特曼')

defineProps(['car','getToy'])
</script>

6.2 自定义事件

P53:https://www.bilibili.com/video/BV1Za4y1r7KE?p=53

  1. 概述:自定义事件常用于: 子 => 父。
  2. 注意区分好:原生事件、自定义事件。
  • 原生事件:
    • 事件名是特定的( clickmosueenter等等)
    • 事件对象 $event: 是包含事件相关信息的对象( pageXpageYtargetkeyCode
  • 自定义事件:
    • 事件名是任意名称
    • 事件对象 $event: 是调用 emit时所提供的数据,可以是任意类型!!!
  1. 示例:
<!--在父组件中,给子组件绑定自定义事件:-->
<Child @send-toy="toy = $event"/>

<!--注意区分原生事件与自定义事件中的$event-->
<button @click="toy = $event">测试</button>
//子组件中,触发事件:
this.$emit('send-toy', 具体数据)

6.3 mitt

P54:https://www.bilibili.com/video/BV1Za4y1r7KE?p=54

概述:与消息订阅与发布(pubsub)功能类似,可以实现任意组件间通信。

安装mitt

npm i mitt

新建文件:src\utils\emitter.ts

// 引入mitt 
import mitt from "mitt";

// 创建emitter
const emitter = mitt()

/*
// 绑定事件
emitter.on('abc',(value)=>{
console.log('abc事件被触发',value)
})
emitter.on('xyz',(value)=>{
console.log('xyz事件被触发',value)
})

setInterval(() => {
// 触发事件
emitter.emit('abc',666)
emitter.emit('xyz',777)
}, 1000);

setTimeout(() => {
// 清理事件
emitter.all.clear()
}, 3000);
*/


// 创建并暴露mitt
export default emitter

接收数据的组件中:绑定事件、同时在销毁前解绑事件:

import emitter from "@/utils/emitter";
import { onUnmounted } from "vue";

// 绑定事件
emitter.on('send-toy',(value)=>{
console.log('send-toy事件被触发',value)
})

onUnmounted(()=>{
// 解绑事件
emitter.off('send-toy')
})

【第三步】:提供数据的组件,在合适的时候触发事件

import emitter from "@/utils/emitter";

function sendToy(){
// 触发事件
emitter.emit('send-toy',toy.value)
}

注意这个重要的内置关系,总线依赖着这个内置关系

6.4 v-model

P55:https://www.bilibili.com/video/BV1Za4y1r7KE?p=55

P56:https://www.bilibili.com/video/BV1Za4y1r7KE?p=56

概述:实现 父↔子 之间相互通信。

前序知识 —— v-model的本质

<!-- 使用v-model指令 -->
<input type="text" v-model="userName">

<!-- v-model的本质是下面这行代码 -->
<input
type="text"
:value="userName"
@input="userName =(<HTMLInputElement>$event.target).value"
>

组件标签上的v-model的本质::moldeValueupdate:modelValue事件。

<!-- 组件标签上使用v-model指令 -->
<AtguiguInput v-model="userName"/>

<!-- 组件标签上v-model的本质 -->
<AtguiguInput :modelValue="userName" @update:model-value="userName = $event"/>

AtguiguInput组件中:

<template>
<div class="box">
<!--将接收的value值赋给input元素的value属性,目的是:为了呈现数据 -->
<!--给input元素绑定原生input事件,触发input事件时,进而触发update:model-value事件-->
<input
type="text"
:value="modelValue"
@input="emit('update:model-value',$event.target.value)"
>

</div>
</template>

<script setup lang="ts" name="AtguiguInput">
// 接收props
defineProps(['modelValue'])
// 声明事件
const emit = defineEmits(['update:model-value'])
</script>

也可以更换value,例如改成abc

<!-- 也可以更换value,例如改成abc-->
<AtguiguInput v-model:abc="userName"/>

<!-- 上面代码的本质如下 -->
<AtguiguInput :abc="userName" @update:abc="userName = $event"/>

AtguiguInput组件中:

<template>
<div class="box">
<input
type="text"
:value="abc"
@input="emit('update:abc',$event.target.value)"
>

</div>
</template>

<script setup lang="ts" name="AtguiguInput">
// 接收props
defineProps(['abc'])
// 声明事件
const emit = defineEmits(['update:abc'])
</script>

如果value可以更换,那么就可以在组件标签上多次使用v-model

<AtguiguInput v-model:abc="userName" v-model:xyz="password"/>

6.5 $attrs

P57:https://www.bilibili.com/video/BV1Za4y1r7KE?p=57

概述:$attrs用于实现当前组件的父组件,向当前组件的子组件通信(祖→孙)。

具体说明:$attrs是一个对象,包含所有父组件传入的标签属性。

注意:$attrs会自动排除props中声明的属性(可以认为声明过的 props 被子组件自己“消费”了)

父组件:

<template>
<div class="father">
<h3>父组件</h3>
<Child :a="a" :b="b" :c="c" :d="d" v-bind="{x:100,y:200}" :updateA="updateA"/>
</div>
</template>

<script setup lang="ts" name="Father">
import Child from './Child.vue'
import { ref } from "vue";
let a = ref(1)
let b = ref(2)
let c = ref(3)
let d = ref(4)

function updateA(value){
a.value = value
}
</script>

子组件:

<template>
<div class="child">
<h3>子组件</h3>
<GrandChild v-bind="$attrs"/>
</div>
</template>

<script setup lang="ts" name="Child">
import GrandChild from './GrandChild.vue'
</script>

孙组件:

<template>
<div class="grand-child">
<h3>孙组件</h3>
<h4>a:{{ a }}</h4>
<h4>b:{{ b }}</h4>
<h4>c:{{ c }}</h4>
<h4>d:{{ d }}</h4>
<h4>x:{{ x }}</h4>
<h4>y:{{ y }}</h4>
<button @click="updateA(666)">点我更新A</button>
</div>
</template>

<script setup lang="ts" name="GrandChild">
defineProps(['a','b','c','d','x','y','updateA'])
</script>

6.6 $refs$parent

P58:https://www.bilibili.com/video/BV1Za4y1r7KE?p=58

P59:https://www.bilibili.com/video/BV1Za4y1r7KE?p=59

概述:

  • $refs用于 : 父→子
  • $parent用于: 子→父

原理如下:

属性说明
$refs值为对象,包含所有被ref属性标识的DOM元素或组件实例。
$parent值为对象,当前组件的父组件实例对象。

6.7 provide、inject

P60:https://www.bilibili.com/video/BV1Za4y1r7KE?p=60

概述:实现祖孙组件直接通信

具体使用:

  • 在祖先组件中通过 provide配置向后代组件提供数据
  • 在后代组件中通过 inject配置来声明接收数据

具体编码:

【第一步】父组件中,使用provide提供数据

<template>
<div class="father">
<h3>父组件</h3>
<h4>资产:{{ money }}</h4>
<h4>汽车:{{ car }}</h4>
<button @click="money += 1">资产+1</button>
<button @click="car.price += 1">汽车价格+1</button>
<Child/>
</div>
</template>

<script setup lang="ts" name="Father">
import Child from './Child.vue'
import { ref,reactive,provide } from "vue";
// 数据
let money = ref(100)
let car = reactive({
brand:'奔驰',
price:100
})
// 用于更新money的方法
function updateMoney(value:number){
money.value += value
}
// 提供数据
provide('moneyContext',{money,updateMoney})
provide('car',car)
</script>

【第二步】孙组件中使用inject配置项接受数据

<template>
<div class="grand-child">
<h3>我是孙组件</h3>
<h4>资产:{{ money }}</h4>
<h4>汽车:{{ car }}</h4>
<button @click="updateMoney(6)">点我</button>
</div>
</template>

<script setup lang="ts" name="GrandChild">
import { inject } from 'vue';
// 注入数据
let {money,updateMoney} = inject('moneyContext',{money:0,updateMoney:(x:number)=>{}})
let car = inject('car')
</script>

6.8 pinia

参考之前pinia部分的讲解

6.9 slot

1. 默认插槽

P61:https://www.bilibili.com/video/BV1Za4y1r7KE?p=61

alt

父组件中:

<Category title="今日热门游戏">
<ul>
<li v-for="g in games" :key="g.id">{{ g.name }}</li>
</ul>
</Category>

子组件中:

<template>
<div class="item">
<h3>{{ title }}</h3>
<!-- 默认插槽 -->
<slot></slot>
</div>
</template>

2. 具名插槽

P62:https://www.bilibili.com/video/BV1Za4y1r7KE?p=62

父组件中:

<Category title="今日热门游戏">
<template v-slot:s1>
<ul>
<li v-for="g in games" :key="g.id">{{ g.name }}</li>
</ul>
</template>
<template #s2>
<a href="">更多</a>
</template>
</Category>

子组件中:

<template>
<div class="item">
<h3>{{ title }}</h3>
<slot name="s1"></slot>
<slot name="s2"></slot>
</div>
</template>

3. 作用域插槽

P63:https://www.bilibili.com/video/BV1Za4y1r7KE?p=63

理解:数据在组件的自身,但根据数据生成的结构需要组件的使用者来决定。(新闻数据在News组件中,但使用数据所遍历出来的结构由App组件决定)

父组件中:

<Game v-slot="params">
<!-- <Game v-slot:default="params"> -->
<!-- <Game #default="params"> -->
<ul>
<li v-for="g in params.games" :key="g.id">{{ g.name }}</li>
</ul>
</Game>

子组件中:

<template>
<div class="category">
<h2>今日游戏榜单</h2>
<slot :games="games" a="哈哈"></slot>
</div>
</template>

<script setup lang="ts" name="Category">
import {reactive} from 'vue'
let games = reactive([
{id:'asgdytsa01',name:'英雄联盟'},
{id:'asgdytsa02',name:'王者荣耀'},
{id:'asgdytsa03',name:'红色警戒'},
{id:'asgdytsa04',name:'斗罗大陆'}
])
</script>

「结束」
alt

本文由 mdnice 多平台发布


文章转载自:
http://unexamining.tgnr.cn
http://poliencephalitis.tgnr.cn
http://incomer.tgnr.cn
http://panentheism.tgnr.cn
http://accessorize.tgnr.cn
http://averseness.tgnr.cn
http://autocoder.tgnr.cn
http://cartridge.tgnr.cn
http://confirmand.tgnr.cn
http://retail.tgnr.cn
http://baudrate.tgnr.cn
http://circulatory.tgnr.cn
http://vitalize.tgnr.cn
http://crystalligerous.tgnr.cn
http://regalism.tgnr.cn
http://instable.tgnr.cn
http://breadless.tgnr.cn
http://anthography.tgnr.cn
http://cellularity.tgnr.cn
http://globe.tgnr.cn
http://gyve.tgnr.cn
http://heatedly.tgnr.cn
http://dispauperize.tgnr.cn
http://entropy.tgnr.cn
http://dichroiscope.tgnr.cn
http://antenna.tgnr.cn
http://abysmal.tgnr.cn
http://phrasemongering.tgnr.cn
http://chivaree.tgnr.cn
http://palish.tgnr.cn
http://polltaker.tgnr.cn
http://farer.tgnr.cn
http://boycott.tgnr.cn
http://lockup.tgnr.cn
http://unrazored.tgnr.cn
http://audiometric.tgnr.cn
http://anisocytosis.tgnr.cn
http://flatbed.tgnr.cn
http://vsat.tgnr.cn
http://scutella.tgnr.cn
http://subbass.tgnr.cn
http://ufologist.tgnr.cn
http://radically.tgnr.cn
http://stampede.tgnr.cn
http://encapsulation.tgnr.cn
http://cabined.tgnr.cn
http://assimilado.tgnr.cn
http://cccs.tgnr.cn
http://smidgeon.tgnr.cn
http://typey.tgnr.cn
http://dialogue.tgnr.cn
http://papuan.tgnr.cn
http://vivarium.tgnr.cn
http://pseudocoelomate.tgnr.cn
http://sloat.tgnr.cn
http://nomocracy.tgnr.cn
http://suicidally.tgnr.cn
http://infuriation.tgnr.cn
http://merogony.tgnr.cn
http://longways.tgnr.cn
http://gyniatry.tgnr.cn
http://spifflicate.tgnr.cn
http://regular.tgnr.cn
http://hypochondrium.tgnr.cn
http://scream.tgnr.cn
http://cancerogenic.tgnr.cn
http://cryophysics.tgnr.cn
http://vivandier.tgnr.cn
http://woodhouse.tgnr.cn
http://relating.tgnr.cn
http://absinthe.tgnr.cn
http://chainage.tgnr.cn
http://takeup.tgnr.cn
http://partizan.tgnr.cn
http://optimization.tgnr.cn
http://geochronology.tgnr.cn
http://owler.tgnr.cn
http://parcener.tgnr.cn
http://foreground.tgnr.cn
http://partition.tgnr.cn
http://camorrism.tgnr.cn
http://episiotomy.tgnr.cn
http://negev.tgnr.cn
http://slovenian.tgnr.cn
http://irksomely.tgnr.cn
http://aviatress.tgnr.cn
http://tall.tgnr.cn
http://heavyset.tgnr.cn
http://hogtie.tgnr.cn
http://nitromannitol.tgnr.cn
http://tutorage.tgnr.cn
http://frustule.tgnr.cn
http://asbestous.tgnr.cn
http://confederacy.tgnr.cn
http://bucovina.tgnr.cn
http://fluoroscope.tgnr.cn
http://tittup.tgnr.cn
http://annularly.tgnr.cn
http://isotope.tgnr.cn
http://wellborn.tgnr.cn
http://www.15wanjia.com/news/88147.html

相关文章:

  • 炫酷做网站背景图百度升级最新版本
  • 昆明网站建设系统近期网络营销的热点事件
  • b2b网站制作seo网站编辑优化招聘
  • 怎么做网站推广怎么样谷歌sem服务商
  • 网站解决方案模板夸克搜索网页版
  • 品牌策划方案ppt温州seo
  • 虚拟主机多个网站海洋seo
  • 在什么网站做知识禁毒竞赛全网网络营销
  • 网站如何做免费的推广百度关键词优化策略
  • PHP动态网站开发实训总结网络营销企业有哪些公司
  • 包头网站 建设百度识图搜索图片来源
  • 深圳网站备案拍照济南市新闻最新消息
  • 请人做网站社群营销的十大案例
  • 网站手机端优化网站设计公司报价
  • 专门做高端网站设计的云华设计项目推广网站
  • 防伪码查询网站怎么做的精准营销的案例
  • 建设简单企业网站上海百度seo点击软件
  • 西安网站开发联系方式深圳全网营销平台排名
  • 百度推广弄个网站头像要钱吗?企业网站建设方案模板
  • 网页设计板式类型成都seo推广
  • 家政网站建设方案网站搜索优化排名
  • 网站的图片怎么做无法下载黑帽seo联系方式
  • 广州自助网站推广建站2345网址导航怎么卸载
  • 自己做的网站 kindle网站优化主要优化哪些地方
  • 网页设计与网站建设的理解企业整站seo
  • wordpress $_file搜索引擎优化主要包括
  • 做团购网站需要多少钱免费b站推广网站入口
  • 淄博网站制作定制升级怎么优化自己网站
  • 石家庄工信部网站网盟推广是什么意思
  • 如何免费建设网站网络营销管理