vue2
props: {
//下拉列表
list: {
type: Array,
default: () => [],
},
},
vue3
const props = defineProps({
//下拉列表
list: {
type: Array,
default: () => [],
},
});
vue2
data() {
return {
show: false, //展示下拉列表
};
},
vue3
const state = reactive({
show: false, //展示下拉列表
});
watch: {
show: {
handler(n) {
this.$emit("on-visible", n);
},
},
},
const emits = defineEmits(["on-change", "on-visible"]);
emits("on-visible", n);
//父组件
<BaseDropSelect
:list.sync="dropList"
/>
//子组件
const newList = [...this.list];
newList[index].isCheck = !e.isCheck;
this.$emit("update:list", newList);
//父组件
<BaseDropSelect
v-model:list="dropList"
/>
//子组件
const emits = defineEmits(["update:list"]);
emits("update:list", newList);
computed: {
checkdList() {
return this.list.filter((i) => i.isCheck);
},
},
const checkdList = computed(() => {
return props.list.filter((i) => i.isCheck);
});
!this.checkdList.length
!checkdList.value.length
watch: {
show: {
handler(n) {
this.$emit("on-visible", n);
},
deep: true, // 深度监听
immediate: true, // 初次监听即执行
},
},
watch(
() => state.show,
(n) => {
emits("on-visible", n);
},
{ immediate: true, deep: true },
);
require("@/assets/images/integratedDisasterControl/base/dispatch/mapIcon/all_check.png");
/**
* 获取静态文件
* @param {*} url 文件具体路径
* @param {*} type 文件路径assets下对应的文件夹名称
* @returns
*/
export const getAssetsFile = (url, type) => {
return new URL(`../assets/${type}/${url}`, import.meta.url).href;
};
getAssetsFile("dispatch/mapIcon/all_check.png", "images")
methods: {
handleShow() {
this.show = !this.show;
},
},
const handleShow = () => {
state.show = !state.show;
};
this.handleShow();
handleShow()
this.handleShow();
handleShow()
<template>
<!-- 模板内容 -->
</template>
<script>
// 导入相关依赖
import SomeComponent from '@/components/SomeComponent';
export default {
name: 'MyComponent',
components: {
SomeComponent,
},
props: {
},
data() {
return {
};
},
computed: {
},
watch: {
propA(newValue, oldValue) {
// 监听 propA 的变化
},
},
methods: {
handleClick() {
// 处理点击事件
},
},
filters: {
formatText(value) {
// 格式化文本
},
},
directives: {
customDirective(el, binding) {
// 自定义指令逻辑
},
},
beforeCreate() {
// 生命周期钩子函数
},
created() {
// 生命周期钩子函数
},
beforeMount() {
// 生命周期钩子函数
},
mounted() {
// 生命周期钩子函数
},
beforeUpdate() {
// 生命周期钩子函数
},
updated() {
// 生命周期钩子函数
},
beforeDestroy() {
// 生命周期钩子函数
},
destroyed() {
// 生命周期钩子函数
},
};
</script>