vue3写法

一.  <script setup>

1. 引入组件
import Head from "./conponents/head.vue"
2. 声明变量
// 引入 ref
import { ref } from 'vue'
const isNeedNav = ref(true)
3. 声明方法
const changeLossd = () => {
    lossdVisible.value = !lossdVisible.value
}
4.生命钩子函数
onBeforeMount(() => {})
onMounted(() => {})
onBeforeUpdate(() => {})
onUpdated(() => {})
onBeforeUnmount(() => {})
onUnmounted(() => {})
5.父传子参数

父:

<Body :twentyFour="twentyFour"></Body>

子:

const porps = defineProps({
    twentyFour: String,
})

JS 中取值:

porps.twentyFour

HTML 中取值:

{{ twentyFour }}
6.父传子方法

父:

 <Body @changeInYear="changeInYear" ></Body>

子:

const emit = defineEmits(['changeInYear']); //声明emit
emit('changeInYear')
7.watch监听
import { watch } from 'vue'

watch(() => chooseNow.value, () => {
    
})
8.css深度监听
:deep(.el-table tr) {
    background: transparent;
}

二.  export default

1. 引入组件
import switchRoom from './switchRoom.vue'
export default {
    components: { electricityLoss, switchRoom },
}
2. 声明变量
import { ref } from 'vue'
export default {
    setup(props, contont) {
        const chooseNow = ref("用电损耗")

        return {
            chooseNow,
        }
    }
}
3. 声明方法
export default {
    setup(props, contont) {
        const changeCom = (name) => {
            chooseNow.value = name
        }
        return {
            changeCom,
        }
    }
}
4.生命钩子函数
import {
onBeforeMount,
onMounted,
onBeforeUpdate,
onUpdated,
onBeforeUnmount,
onUnmounted,
} from 'vue'
onBeforeMount(() => {})
onMounted(() => {})
onBeforeUpdate(() => {})
onUpdated(() => {})
onBeforeUnmount(() => {})
onUnmounted(() => {})
5.父传子参数

父:

<inYearDialog :inYearVisible="inYearVisible" :title='title'></inYearDialog>

子:

props: {
    inYearVisible: Boolean,
    title: String
},

JS 中取值:

setup(props, contont) {
        onMounted(() => {
            consoloe.log(props.inYearVisible)
        })
}

HTML 中取值:

{{ inYearVisible }}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值