sonicsunsky
sonicsunsky
  • 发布:2020-10-08 15:55
  • 更新:2022-02-21 14:16
  • 阅读:12060

uni-app 通过vue-cli创建的vue3.0项目不支持的一些功能总结

分类:uni-app
  1. 通过defineComponents定义的组件导出的时候会提示"export 'defineComponent' was not found in 'vue'
    小程序开发工具会报错 TypeError: Object(...) is not a function

    <script>  
    import { defineComponent, toRefs } from 'vue'  
    export default defineComponent({  
    name: 'xxx',  
    props: {  
        tips: {  
            type: Array,  
            default: () => {  
                return []  
            }  
        }  
    },  
    setup(props, context) {  
        return {  
            ...toRefs(props)  
        }  
    }  
    })  
    </script>
  2. import { getCurrentInstance } from vue,uni-app框架下在vue中暂时拿不到getCurrentInstance这个函数,无法访问到getCurrentInstance

  3. v-model双向数据绑定默认用的还是原来的value属性和input事件,不是vue3.0中的v-bind:modelValue="xxx"的modelValue属性和update:modelValue事件;

  4. ref无法获取组件实例ref引用;

    
    <share ref="shareRef" ></share>  
    const shareRef = ref(null)  
    onMounted(() => {  
    console.log('onMounted, shareRef: ', shareRef.value)//此处打印null,undefined  
    })  
4 关注 分享
ian7 毛学生 DCloud_heavensoft 3***@qq.com

要回复文章请先登录注册

1***@qq.com

1***@qq.com

支付宝小程序真机打开分包页面报错了
2022-02-21 14:16
miniprogrammer

miniprogrammer

请问一下,uni-app 通过vue-cli创建的vue3.0项目怎么传入环境变量啊,之前在运行或者打包脚本添加cross-env NODE_ENV=test就可以传入环境变量,现在咋都不行,用vue3的那种方式添加.env.test文件也不行
2021-12-15 10:49
t***@163.com

t***@163.com

回复 战斗猪 :
不好意思,后面用uniapp有点少,没怎么看,刚看见
2021-05-18 16:51
2***@qq.com

2***@qq.com

ref 获取 组件实例什么时候支持啊
2021-03-26 09:45
战斗猪

战斗猪

更新:最新版今天已经支持了
2021-02-03 16:55
战斗猪

战斗猪

回复 战斗猪 :
搞定了,加const getCurrentInstance = () => currentInstance || currentRenderingInstance这一行,然后export 加上getCurrentInstance就可以了
2021-02-03 09:17
战斗猪

战斗猪

回复 t***@163.com :
你这里怎么搞定的?
2021-02-02 14:49
sonicsunsky

sonicsunsky (作者)

回复 毛学生 :
使用options api的话是可以使用this的,在setup里边是不行的,得用getCurrentInstance().ctx才行
2020-11-27 14:58
毛学生

毛学生

onMounted使用箭头函数怎么可能有this,并且钩子函数就已经抛弃使用this了
2020-11-19 16:55
t***@163.com

t***@163.com

回复 sonicsunsky :
找的方法了,看了下uniapp的vue代码,有setCurrentInstance没有getCurrentInstance,我直接把vue官方源码里的getCurrentInstance直接复制过来搞定了,希望官方能在uniapp vue3正式版里补上这个功能
2020-10-30 10:57