首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在返回渲染函数(例如JSX)时,将vue-devtools与composition api一起使用

在返回渲染函数(例如JSX)时,将vue-devtools与composition api一起使用
EN

Stack Overflow用户
提问于 2020-05-20 18:39:41
回答 1查看 417关注 0票数 2

由于切换到composition-api并返回一个render function (在我的例子中,使用JSX with TypeScript构造以允许在模板中输入支持),我已经失去了让vue-devtools检查computed properties的能力。这是因为它们不再由组件直接公开(道具仍然可用)。

如何在模板中获得良好的TypeScript支持,同时保留vue-devtools检查计算属性的能力?

下面是一个使用.vue文件的例子,它对vue-devtools很友好,但在模板中没有TypeScript支持:

SomeComponent.vue

代码语言:javascript
复制
<template>
  <div>
    <ul>
      <li>{{ computedProperty }}</li>
    </ul>
  </div>
</template>

<script lang="ts">
  export default defineComponent({
    name: "SomeComponent",
    props: { 
      // ...
    },
    setup(props, ctx) {
      const computedProperty = computed(() => {
        // return ...some calc
      })

      return {
        computedProperty
      }
    }
  })
</script>

下面是一个使用.tsx文件的示例,该文件在模板中具有适当的TypeScript支持,但是vue-devtools不再能够直接检查computedProperty

SomeComponent.tsx

代码语言:javascript
复制
export default defineComponent({
    name: "SomeComponent",
    props: { 
      // ...
    },
    setup(props, ctx) {
      const computedProperty = computed(() => {
        // return ...some calc
      })

      return () => (
        <div>
          <ul>
            <li>{ computedProperty.value }</li>
          </ul>
        </div>
      )
    }
  })

我怎样才能两全其美呢?

EN

回答 1

Stack Overflow用户

发布于 2021-06-08 14:19:40

代码语言:javascript
复制
export default defineComponent({
    name: "SomeComponent",
    props: { 
      // ...
    },
    setup(props, ctx) {
      const computedProperty = computed(() => {
        // return ...some calc
      })

      return { computedProperty }
    },
    render() {
      return (
        <div>
          <ul>
            <li>{ this.computedProperty.value }</li>
          </ul>
        </div>
      )
    }
  })
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/61911008

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档