vue3.2 新特性

配置

vue3.2 + ts + volar ( 需要禁用vetur)

案例

父组件

<template>
  <div class="home">
    <img alt="Vue logo" src="../assets/logo.png" />
    <HelloWorld @changeInfo="changeInfo" :info="info" />
  </div>
</template>

<script lang="ts" setup>
import { ref } from "vue";
import HelloWorld from "@/components/HelloWorld.vue"; // 不在需要注册

const info = ref("HelloWorld");
const changeInfo = (val: string) => {
  info.value = val;
};
</script>

子组件

<template>
  <div class="about">{{ username }}---{{ info }}</div>
  <button @click="changeInfo">修改info</button>
</template>
<script lang="ts" setup>
import { reactive, toRefs, defineEmits } from "vue";
const props = defineProps({
  info: {
    type: String,
    default: "default",
  },
});

const emit = defineEmits(["changeInfo"]);

// 完整写法
const emits = defineEmits<{
  // 文件提交上传前的钩子函数
  // return true 提交上传
  // return false 取消上传
  (e: "on-uploaded", data: i_file_data): void;
  // 文件上传最终的钩子函数
  (e: "before-upload", data: i_file_data): boolean;
}>();

const state = reactive({
  username: "hhh",
});

const changeInfo = () => {
  emit("changeInfo", "newInfo");
};

let { username } = toRefs(state);
</script>

<style lang='scss' scoped>
</style>

PropType

  props: {
    activeData: {
      type: Object as PropType<i_item>,
      default: null,
    },
  },

defineEmit

const emits = defineEmits<{ (e: "handleImg", id: number): void }>();

其他语法

<script setup>
import { useSlots, useAttrs } from 'vue'

const slots = useSlots()
const attrs = useAttrs()
</script>

setup 下怎么注册组件

ref 直接作用于css

const moveTime = ref<string>();
  animation-duration: v-bind(moveTime);
  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值