最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

關(guān)于vue3?解決getCurrentInstance?打包后線上環(huán)境報(bào)錯(cuò)問(wèn)題

 更新時(shí)間:2022年05月24日 14:55:42   作者:船長(zhǎng)在船上  
這篇文章主要介紹了vue3?解決getCurrentInstance?打包后線上環(huán)境報(bào)錯(cuò)問(wèn)題,本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下

getCurrentInstance

getCurrentInstance 支持訪問(wèn)內(nèi)部組件實(shí)例。

WARNING

getCurrentInstance 只暴露給高階使用場(chǎng)景,典型的比如在庫(kù)中。強(qiáng)烈反對(duì)在應(yīng)用的代碼中使用 getCurrentInstance。請(qǐng)不要把它當(dāng)作在組合式 API 中獲取 this 的替代方案來(lái)使用。

import { getCurrentInstance } from 'vue'
const MyComponent = {
  setup() {
    const internalInstance = getCurrentInstance()
 
    internalInstance.appContext.config.globalProperties // 訪問(wèn) globalProperties
  }
}

打印信息: 

getCurrentInstance 只能在setup或生命周期鉤子中調(diào)用。 

如需在 setup或生命周期鉤子外使用,請(qǐng)先在 setup 中調(diào)用 getCurrentInstance() 獲取該實(shí)例然后再使用。

setup() {
    const internalInstance = getCurrentInstance() // 有效
 
    const id = useComponentId() // 有效
 
    const handleClick = () => {
      getCurrentInstance() // 無(wú)效
      useComponentId() // 無(wú)效
 
      internalInstance // 有效
    }
}

本地使用示例:

當(dāng)前在本地使用沒(méi)有問(wèn)題,線上環(huán)境會(huì)報(bào)錯(cuò),不建議使用

<script>
    import {getCurrentInstance} from "vue";
    export default {
      components: {
      },
      setup() {
         const {ctx} = getCurrentInstance();
         console.log(ctx,"屬性1")
         
  
      }
</script>

查看打?。?/p>

項(xiàng)目中使用:表單table列表查詢

方法1: 不推薦

setup() {
         const {ctx} = getCurrentInstance();
         console.log(ctx,"屬性1")
         
        //表單查詢方法
        const submitForm = (formName) =>{
          ctx.$refs[formName].validate(valid => {
            if (valid) {
              ruleForm.pageNum = 1;
              getTableData();
            } else {
              console.log("error submit!!");
              return false;
            }
          });
        }
}

 方法2:推薦此用法,才能在你項(xiàng)目正式上線版本正常運(yùn)行,避免線上報(bào)錯(cuò)問(wèn)題

解決:用proxy代替ctx。在結(jié)構(gòu)的時(shí)候直接將proxy解構(gòu)出來(lái)

setup() {
         let {proxy} = getCurrentInstance();
        console.log(proxy,"屬性2");
         
        //表單查詢方法
        const submitForm = (formName) =>{
          proxy.$refs[formName].validate(valid => {
            if (valid) {
              ruleForm.pageNum = 1;
              getTableData();
            } else {
              console.log("error submit!!");
              return false;
            }
          });
        }
}

打?。?/p>

到此這篇關(guān)于vue3 解決getCurrentInstance 打包后線上環(huán)境報(bào)錯(cuò)問(wèn)題的文章就介紹到這了,更多相關(guān)vue3 getCurrentInstance 打包報(bào)錯(cuò)內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

最新評(píng)論

精河县| 海安县| 进贤县| 广南县| 大名县| 阿克苏市| 大兴区| 乌拉特中旗| 通河县| 穆棱市| 尚义县| 泾阳县| 台北市| 银川市| 揭阳市| 繁昌县| 黔东| 合水县| 临清市| 崇文区| 贵定县| 南平市| 太白县| 东山县| 福海县| 德州市| 密云县| 绩溪县| 临泽县| 嘉定区| 射洪县| 山东| 鄄城县| 昌宁县| 宁海县| 新津县| 长白| 嫩江县| 安义县| 东莞市| 西和县|