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

无域名网站 能否被百度网站建设公司一月赚多少

无域名网站 能否被百度,网站建设公司一月赚多少,wordpress注册弹出框,郑州经济技术开发区实验中学文章目录 一、defineProps() 和 defineEmits()二、defineModel() 的双向绑定2.1、基础示例2.2、定义类型2.3、声明prop名称2.4、其他声明2.5、绑定多个值2.6、修饰符和转换器2.7、修饰符串联 一、defineProps() 和 defineEmits() 组件之间通讯,通过 props 和 emits…

文章目录

      • 一、defineProps() 和 defineEmits()
      • 二、defineModel() 的双向绑定
        • 2.1、基础示例
        • 2.2、定义类型
        • 2.3、声明prop名称
        • 2.4、其他声明
        • 2.5、绑定多个值
        • 2.6、修饰符和转换器
        • 2.7、修饰符串联

一、defineProps() 和 defineEmits()

组件之间通讯,通过 props 和 emits 进行通讯,是单向数据流,
子组件不能改变父组件传递给它的 prop 属性,推荐的做法是它抛出事件,通知父组件自行改变绑定的值。

为了在声明 props 和 emits 选项时获得完整的类型推导支持,我们可以使用 defineProps 和 defineEmits API,它们将自动地在 <script setup> 中可用:

  • 父组件:
<template><div><ChildMy v-model:count="count" />{{ count }}</div>
</template><script setup>import ChildMy from './child.vue'import { ref } from 'vue' const count = ref(1)
</script>
  • 子组件:
<template><div>{{ props.count }}<button @click="updatedCount">child btn</button></div>
</template><script setup>
const props = defineProps(["count"]);
const emit = defineEmits(["update:count"]);const updatedCount = () => {emit('update:count', props.count + 1)
}
</script>
  • defineProps 和 defineEmits 都是只能在

二、defineModel() 的双向绑定

这个宏可以用来声明一个双向绑定 prop,通过父组件的 v-model 来使用。

在底层,这个宏声明了一个 model prop 和一个相应的值更新事件。如果第一个参数是一个字符串字面量,它将被用作 prop 名称;否则,prop 名称将默认为 “modelValue”。在这两种情况下,你都可以再传递一个额外的对象,它可以包含 prop 的选项和 model ref 的值转换选项。

defineModel() 的双向绑定是在编译之后,创建了一个model的ref变量以及一个modelValue的props,并且watch了props中的modelValue;当子组件中的modelValue更新时,会触发update:modelValue事件,当父组件接收到这个事件时候,同时更新父组件的变量。

2.1、基础示例
  • 父组件:
<template><div><ChildMy v-model="message"/>{{ message }}</div>
</template><script setup>import ChildMy from './child.vue'import { ref } from 'vue' const message = ref('hello')
</script>
  • 子组件:
<template><div>{{ message }}<button @click="updatedMsg">child btn</button></div>
</template><script setup>
const message = defineModel()const updatedMsg = () => {message.value = `world`
}
</script>
2.2、定义类型
  • 子组件:
<template><div>{{ message }}<button @click="updatedMsg">child btn</button></div>
</template><script setup>
const message = defineModel({ type: String })const updatedMsg = () => {message.value = `world`
}
</script>
2.3、声明prop名称
  • 父组件:
<template><div><ChildMy v-model:count="count"/>{{ count }}</div>
</template><script setup>import ChildMy from './child.vue'import { ref } from 'vue' const count = ref(1)
</script>
  • 子组件:
<template><div>{{ count }}<button @click="updatedCount">child btn</button></div>
</template><script setup>
const count = defineModel("count")
const updatedCount = () => {count.value ++
}
</script>
2.4、其他声明
  • 子组件:
<template><div>{{ count }}<button @click="updatedCount">child btn</button></div>
</template><script setup>
const count = defineModel("count", { type: Number, default: 0 , required: true})
const updatedCount = () => {count.value ++
}
</script>
2.5、绑定多个值
  • 父组件:
<template><div><ChildMy v-model:count="count" v-model:person="person" />{{ person }} - {{ count }}</div>
</template><script setup>
import ChildMy from './components/child.vue'
import { ref,reactive  } from 'vue'
const count = ref(1)
const person = reactive ({name: 'Lucy',age: 11})
</script>
  • 子组件:
<template><div>{{ person }} - {{ count }}<button @click="updatedData">child btn</button></div>
</template><script setup>
const person = defineModel("person")
const count = defineModel("count")const updatedData = () => {count.value ++person.value.age = 22person.value.name = "lilei"
}
</script>
2.6、修饰符和转换器

为了获取 v-model 指令使用的修饰符,我们可以像这样解构 defineModel() 的返回值:

const [modelValue, modelModifiers] = defineModel()

当存在修饰符时,我们可能需要在读取或将其同步回父组件时对其值进行转换。我们可以通过使用 get 和 set 转换器选项来实现这一点:

  • 父组件:
<template><div><ChildMy v-model.trim="message"/>{{ message }}</div>
</template><script setup>import ChildMy from './child.vue'import { ref } from 'vue' const message = ref(' hello ')
</script>
  • 子组件:
<template><div>{{ message }}<button @click="updatedMsg">child btn</button></div>
</template><script setup>
const [message, modelModifiers] = defineModel({set(value) {if (modelModifiers.trim) {value=value?.trim()}return value}
})const updatedMsg = () => {message.value += ` world`
}
</script>
2.7、修饰符串联
  • 父组件:
<template><div><ChildMy v-model.trim.lowercase="message"/>{{ message }}</div>
</template><script setup>import ChildMy from './child.vue'import { ref } from 'vue' const message = ref('Hello')
</script>
  • 子组件:
<template><div>{{ message }}<button @click="updatedMsg">child btn</button></div>
</template><script setup>
const [message, modelModifiers] = defineModel({get(value) {if (modelModifiers.trim) {value=value?.trim()}if (modelModifiers.lowercase) {value=value?.toLowerCase();}return value},set(value) {if (modelModifiers.trim) {value=value?.trim()}if (modelModifiers.lowercase) {value=value?.toLowerCase();}return value}
})const updatedMsg = () => {message.value += `World`
}
</script>
http://www.yayakq.cn/news/710129/

相关文章:

  • 网站布局框架城阳网站建设
  • 起点签约的书网站给做封面吗有赞商城小程序入口
  • 常州制作网站软件服装网站设计模板
  • 酒店网站设计方案长沙室内设计公司排名
  • 网站access数据库被攻击不断增大怎样登录沈阳科技网站
  • 网站制作流程详解(学做网站第一步)ai网页生成
  • 智能建站的优势和不足网站开发要写代码吗
  • 用c 来建设网站海南百度竞价推广
  • 永康市网站建设制作家里的电脑ip做网站
  • 辅助网站怎么做的东至县住房和城乡建设网站
  • 福建省建设监理公司网站电商网站
  • 网站原型是以下哪层设计的结果宁波网站seo哪家好
  • 企业查询网站企查查大连网站专业制作
  • 个人网站怎样申请管理系统有哪些
  • 营口建网站的公司网页设计素材
  • 宜昌市做网站的公司免费纯ftp空间
  • 汕尾网站设计公司网站程序
  • 网站空格 教程粉末涂料 技术支持 东莞网站建设
  • 灵璧做网站公司怎么制作软件app教程
  • 网站建设结项报告网站需要改进的地方
  • 做百度网站那家好网页设计商城网站建设
  • 自建网站步骤网站开发建设技术规范书
  • 织梦网站内容管理系统做网站的公司怎么样
  • 昆山营销型网站建设做资源分享网站
  • 好用的h5网站模板下载网站后台管理js
  • 大连网站建设报价优质商家社交网站的建设现状
  • html好看的网站的代码跨境电商产品开发流程
  • dede网站头部不显示调用的名称网站开发命名规范
  • 网站 后台 设计个人网站备案后做游戏
  • 现在做网络推广网站建设怎么样无锡企业网络推广服务