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

怎么做才能提高网站权重黔南州住房和城乡建设局网站

怎么做才能提高网站权重,黔南州住房和城乡建设局网站,wordpress虚拟资源下载源码,医疗设计网站vue2 以及 vue3 自定义组件使用 v-model使用默认值以及自定义事件 1. vue2 自定义组件的 v-model vue2官网,自定义组件官方解释:一个组件上的 v-model 默认会利用名为 value 的 prop 和名为 input 的事件上代码代码中使用了 element-ui 子组件 使用默…

vue2 以及 vue3 自定义组件使用 v-model使用默认值以及自定义事件

1. vue2 自定义组件的 v-model

  1. vue2官网,自定义组件
  2. 官方解释:一个组件上的 v-model 默认会利用名为 value 的 prop 和名为 input 的事件
  3. 上代码
  4. 代码中使用了 element-ui

子组件 使用默认 value 和input 事件


// dialog.vue<template><el-dialogtitle="提示":visible.sync="value"width="30%":before-close="handleClose"><span>2222222</span><span slot="footer" class="dialog-footer"><el-button @click="handleClose">取 消</el-button><el-button type="primary" @click="submit">确 定</el-button></span></el-dialog>
</template>
<script>
export default {props: {value: {type: Boolean,default: () => false,},},methods: {// 取消handleClose() {// 弹窗关闭 默认的event事件为 inputthis.$emit("input", false);},// 提交submit() {},},
};
</script>

父组件使用

<template><div><el-button type="primary" @click="visible = true">打开弹窗</el-button> <Dialog v-model="visible"></Dialog></div>
</template>
<script>
import Dialog from "@/components/dialog.vue";
export default {components: {Dialog,},data() {return {visible: false,};},methods:{changeDialog(data){console.log(data)this.text = data},}
};
</script>
  1. 官方解释后半段:自定义 prop 和 事件名 像单选框、复选框等类型的输入控件可能会将 value attribute 用于不同的目的。model 选项可以用来避免

子组件

<template><el-dialogtitle="提示":visible.sync="visible"width="30%":before-close="handleClose"><span>2222222</span><span slot="footer" class="dialog-footer"><el-button @click="handleClose">取 消</el-button><el-button type="primary" @click="submit">确 定</el-button></span></el-dialog>
</template>
<script>
export default {model: {prop: "visible",event: "update", // 为了避免事件名称冲突 此处可以自定义方法名},props: {visible: {type: Boolean,default: () => false,},},data() {return {};},methods: {// 取消handleClose() {//   使用自定义方法名 和上面这行代码效果一致this.$emit("update", false);},// 提交submit() {},},
};
</script>

父组件

<template><div><el-button type="primary" @click="visible = true">打开弹窗</el-button> <Dialog v-model="visible"></Dialog></div>
</template>
<script>
import Dialog from "@/components/dialog.vue";
export default {components: {Dialog,},data() {return {visible: false,};},methods:{changeDialog(data){console.log(data)this.text = data},}
};
</script>

2. vue3 自定义组件的 v-model

  1. vue3官网,自定义组件
  2. 官方解释:默认情况下,v-model 在组件上都是使用 modelValue 作为 prop,并以 update:modelValue 作为对应的事件
  3. 上代码
  4. 代码中使用了 element-plus

子组件 使用默认 modelValue 和 update:modelValue事件

// 子组件   dialog.vue
<template><el-dialogv-model="props.modelValue"title="Tips"width="30%":before-close="handleClose"><span>This is a message</span><template #footer><span class="dialog-footer"><el-button @click="handleClose">取消</el-button><el-button type="primary" @click="submit"> 确定 </el-button></span></template></el-dialog>
</template><script setup lang="ts">
// 接受数据
const props = defineProps({modelValue: {type: Boolean,default: () => false,},
});// 注册事件
const emit = defineEmits(["update:modelValue"]);// 关闭
const handleClose = () => {emit("update:modelValue", false);
};
// 提交
const submit = () => {};
</script>

父组件

<template><div><el-button text @click="visible = true"> 打开弹窗 </el-button><!-- 第一种方式 使用默认方式 --><Dialog v-model="visible"></Dialog></div>
</template><script setup lang="ts">
import Dialog from "@/components/dialog.vue";
import { ref } from "vue";const visible = ref(false);
</script>
  1. 官方解释后半段:自定义 prop 和 事件名 我们可以通过给 v-model 指定一个参数来更改这些名字

子组件

<template><el-dialogv-model="props.visible"title="Tips"width="30%":before-close="handleClose"><span>This is a message</span><template #footer><span class="dialog-footer"><el-button @click="handleClose">取消</el-button><el-button type="primary" @click="submit"> 确定 </el-button></span></template></el-dialog>
</template><script setup lang="ts">
// 接受数据
const props = defineProps({visible: {type: Boolean,default: () => false,},
});// 注册事件
const emit = defineEmits(["update:visible"]);// 关闭
const handleClose = () => {emit("update:visible", false);
};
// 提交
const submit = () => {};
</script>

父组件

<template><div><el-button text @click="visible = true"> 打开弹窗 </el-button><!-- 第二种方式 自定义props 名称为 visible --><Dialog v-model:visible="visible"></Dialog></div>
</template><script setup lang="ts" name="debounceDirect">
import Dialog from "@/components/dialog.vue";
import { ref } from "vue";const visible = ref(false);
</script>

以上就是vue2或者vue3 自定义组件 v-model 的使用!

http://www.yayakq.cn/news/72787/

相关文章:

  • 全栈工程师是做网站吗优化大师怎么强力卸载
  • 建立网站的英文卖房网站母亲节做什麽活动
  • 网站建设 设备建设l旅游网站目的及功能定位
  • 贵州省和城乡建设厅官方网站古镇小企业网站建设
  • 大型网站建设招商iis 5.1 新建网站
  • 深圳网站软件开发专业微网站建设公司哪家好
  • 太原网站建设开发公司用.net做的网站
  • vps 一个ip 多个网站 软件 linux更新文章时间 wordpress
  • 做阿里巴巴网站应怎样定位390元做微信小程序 公众号 网站
  • 长春企业公司网站建设室内环保网站模板代码
  • 凡科网站产品导航怎么做语言互动网站建设
  • 无极网站建设质量南阳专业网站制作费用
  • 网站自建设需要买什么网页版崩坏星穹铁道
  • 建站导航机械制造网站
  • 华为弹性云做网站怎么做个手机版的网站吗
  • 做微商去哪个网站推广即墨今天新闻大事
  • 网站建设培训班搭建微信网站
  • 网站做后台网络服务提供商
  • 番禺网站开发设计苏州一建建筑集团有限公司
  • 网站建设公司 html5模板北京seo优化网站建设
  • 建设网站怎样提要求做调差问卷的网站
  • 免费自助建设网站长沙网站搭建关键词排名
  • 网站整体架构南昌网站建设方案优化
  • wordpress配置ip访问百度seo营销
  • 网站流量依赖率电子图书馆网站建设
  • 霞浦县网站seo优化排名深圳建设网站费用明细
  • 建立网站的信息集成过程海外社交网络推广
  • 江苏中淮建设集团有限公司网站做教务网站的需求分析
  • 什么网页可以做网站网站建设与应用岗位
  • 网站的留言功能昌平区网站建设公司