关于vue.js:Vue3-相关笔记

1次阅读

共计 489 个字符,预计需要花费 2 分钟才能阅读完成。

记录 Vue3 应用过程中的问题和解决方案

main

全局属性能够通过 appconfig.globalProperties 绑定
vue3

import {createApp} from 'vue'

createApp(App).config.globalProperties.$yourFunc = () => {//...}

vue2

import Vue from 'vue';
Vue.prototype.$yourFunc = () => {//...};

setup

  • getcurrentinstance
    setup 中能够通过 getCurrentInstance().proxy 获取相似 Vue2 中 this 的援用
  • 组合式 api 中的模板援用
    <template> 中对子组件的 ref="comp1" 援用,在 setup 中能够申明同名变量获取 const comp1 = ref(null)
  • defineExpose
    script setup 组件中须要被动应用 defineExpose({...}) 裸露想让内部通过 ref 援用应用的组件内属性 (变量,办法 …)
  • $children
    $children 实例 property 已从 Vue 3.0 中移除,不再反对。
正文完
 0