diff --git a/docs/tutorial/vue-composition-api.md b/docs/tutorial/vue-composition-api.md index c93150dc2d22daa5aeb6db2a0b16a3fa305ddade..c3cf86bcc228d6ff8367fa3100bcb5e81654449d 100644 --- a/docs/tutorial/vue-composition-api.md +++ b/docs/tutorial/vue-composition-api.md @@ -61,11 +61,17 @@ unplugin-vue2-script-setup](https://github.com/antfu/unplugin-vue2-script-setup) import { defineComponent, ref } from '@vue/composition-api' import { onReady } from '@dcloudio/uni-app' export default defineComponent({ - setup() { + setup(_, { expose }) { const title = ref('Hello') onReady(() => { console.log('onReady') }) + // @vue/composition-api 当前版本并无 expose 方法 + if (expose) { + expose({ + title + }) + } return { title } @@ -111,9 +117,24 @@ unplugin-vue2-script-setup](https://github.com/antfu/unplugin-vue2-script-setup) onReady(() => { console.log('onReady') }) + defineExpose({ + // 注意要在 defineExpose 函数外定义 + title + }) ``` ### 与 TypesSript 一起使用 -> 与 Script Setup 一同使用时会禁用默认的类型检查,具体请参考 [unplugin-vue2-script-setup](https://github.com/antfu/unplugin-vue2-script-setup) +* 与 Script Setup 一同使用时会禁用默认的类型检查,具体请参考 [unplugin-vue2-script-setup](https://github.com/antfu/unplugin-vue2-script-setup) +* 即使不与 Script Setup 一同使用但项目为 HBuilderX 创建的工程时,由于 HBuilderX 内置TypesSript插件当前版本较低,也需要禁用默认的类型检查 + +```js + // vue.config.js + module.exports = { + chainWebpack (config) { + // disable type check and let `vue-tsc` handles it + config.plugins.delete('fork-ts-checker') + }, + } +``` \ No newline at end of file