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

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

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

getCurrentInstance

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

WARNING

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

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

打印信息: 

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

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

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

本地使用示例:

當(dāng)前在本地使用沒有問題,線上環(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ò)問題

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

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ò)問題的文章就介紹到這了,更多相關(guān)vue3 getCurrentInstance 打包報(bào)錯(cuò)內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

最新評(píng)論

镇远县| 江津市| 资中县| 玛沁县| 承德市| 姚安县| 吉安县| 历史| 福清市| 佛学| 衡阳市| 本溪| 金山区| 栾川县| 安多县| 康定县| 江西省| 莲花县| 金川县| 鄢陵县| 永靖县| 东城区| 绥阳县| 邛崃市| 景德镇市| 特克斯县| 台中县| 青河县| 甘孜县| 增城市| 柳江县| 奇台县| 双牌县| 平顺县| 甘谷县| 无棣县| 固阳县| 理塘县| 前郭尔| 集贤县| 临湘市|