相关疑难解决方法(0)

在可组合项 vue3 中使用 props

我正在将应用程序从 vue 2 升级到 vue 3,但在可组合项方面遇到了一些问题。我想在可组合项中使用道具,但它似乎不起作用。代码示例是从工作组件中提取的,当我将其留在组件中时,它可以正常工作。

我认为defineProps可组合项不支持,但我不清楚如何处理它。当我传递src参数时,它会失去反应性。

// loadImage.js
import { defineProps, onMounted, ref, watch } from 'vue'

// by convention, composable function names start with "use"
export function useLoadImage() {
  let loadingImage = ref(true)
  let showImage = ref(false)
  const props = defineProps({
    src: String,
  })
  const delayShowImage = () => {
    setTimeout(() => {
      showImage.value = true
    }, 100)
  }
  const loadImage = (src) => {
    let img = new Image()
    img.onload = (e) => …
Run Code Online (Sandbox Code Playgroud)

vue.js vuejs3 vue-composition-api vue-script-setup

11
推荐指数
2
解决办法
1万
查看次数