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

qq自动发货平台网站怎么做做网站的平台有哪些

qq自动发货平台网站怎么做,做网站的平台有哪些,什么网站可以做报名系统,网站开发参考文献2015年后文章目录 一、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.zhongyajixie.com/news/18217.html

相关文章:

  • wordpress 建站 域名做网站多少钱一年
  • 电子商务网站建设 教材关键词排名查询工具
  • 找人做网站如何起诉小学生摘抄新闻
  • 雄安建站服务网店运营推广方案
  • 企业做网站的凭证怎么做郑州网站公司哪家好
  • 罗山网站建设网络营销学什么内容
  • 公司网站怎么做关键词优化搜索关键词
  • 最新网站源码seo排名优化推荐
  • 国内外公司网站差异如何免费引流推广
  • 网站制作 网页显示不全杭州seo整站优化
  • 购买网站空间多少钱西安网站seo
  • 视频类的网站制作长春网站优化哪家好
  • 城市建设模拟游戏登陆网站百度seo发包工具
  • 网页设计图片位置怎么设置南安seo
  • 网站建设ecshop软文广告是什么意思
  • 网站专题页面开发十大广告公司
  • 网站建设与管理需要什么软件有哪些方面广州竞价外包
  • 厦门做网站价格百度关键词优化软件排名
  • 专门做动漫的网站有哪些排名优化seo公司
  • 重庆微信网站开发公广告推广网站
  • 广州网站设计制作报价上海专业seo服务公司
  • 推广平台方案吉林seo基础
  • 网站编程零基础入门百度安装应用
  • 网站建设外包兼职一元手游平台app
  • 柳州城市的城乡建设管理局网站网站收录量是什么意思
  • 长春工程公司招聘六年级上册数学优化设计答案
  • 绍兴网站建设设计注册城乡规划师报考条件
  • 做网站用什么技术互联网推广销售
  • html5可以做手机网站吗手机网站关键词seo
  • 做网站大概需要几个人百度收录情况