diff --git a/components/custom-call-easy-method.uvue b/components/custom-call-easy-method.uvue new file mode 100644 index 0000000000000000000000000000000000000000..a61f5ad6bc16a77681bb4f6ce6efb4c47e0ea246 --- /dev/null +++ b/components/custom-call-easy-method.uvue @@ -0,0 +1,19 @@ + + + \ No newline at end of file diff --git a/pages.json b/pages.json index 08d184b1082c6478322a625113fd8070199ebe04..18f3329a03bc99c9518bda9c44a552fe8e2f80ad 100644 --- a/pages.json +++ b/pages.json @@ -902,6 +902,11 @@ "navigationBarBackgroundColor": "#007AFF" } }, + "easycom": { + "custom": { + "custom-(.*)": "@/components/custom-$1.uvue" + } + }, "uniIdRouter": {}, "condition": { "current": 0, diff --git a/pages/component-instance/methods/call-method-easycom-composition.uvue b/pages/component-instance/methods/call-method-easycom-composition.uvue index eebe2249fc418a66e8edbf4f37019f112e2b43ad..deb6207395aefb28913c0c4ac6c0661ad5b2b2f6 100644 --- a/pages/component-instance/methods/call-method-easycom-composition.uvue +++ b/pages/component-instance/methods/call-method-easycom-composition.uvue @@ -1,11 +1,18 @@ \ No newline at end of file diff --git a/pages/component-instance/methods/call-method-easycom-options.uvue b/pages/component-instance/methods/call-method-easycom-options.uvue index 0a4d35e01a5bf764445a3692d7e61aa881b69414..7e407e24f92c83497dfc0f8613a42094103cde38 100644 --- a/pages/component-instance/methods/call-method-easycom-options.uvue +++ b/pages/component-instance/methods/call-method-easycom-options.uvue @@ -1,6 +1,7 @@ @@ -15,16 +16,19 @@ const delay = (): Promise => export default { data() { return { - callEasyMethod1: null as CallEasyMethodComponentPublicInstance | null + callEasyMethod1: null as CallEasyMethodComponentPublicInstance | null, + customCallEasyMethod1: null as CustomCallEasyMethodComponentPublicInstance | null, } }, onReady() { // 通过组件 ref 属性获取组件实例, 组件标签名首字母大写,驼峰+ComponentPublicInstance this.callEasyMethod1 = this.$refs['callEasyMethod1'] as CallEasyMethodComponentPublicInstance + this.customCallEasyMethod1 = this.$refs['customCallEasyMethod1'] as CustomCallEasyMethodComponentPublicInstance this.call() }, methods: { async call(): Promise { + this.callCustomMethod() this.callMethod1() await delay() this.callMethod2() @@ -61,7 +65,15 @@ export default { callMethodTest(text: string): string | null { const result = this.callEasyMethod1?.foo5?.(text) as string return result - } + }, + callCustomMethod() { + // 调用组件的 foo 方法 + this.customCallEasyMethod1?.foo?.() + }, + callCustomMethodTest(): string | null { + const result = this.customCallEasyMethod1?.foo?.() as string + return result + }, } } \ No newline at end of file diff --git a/pages/component-instance/methods/call-method-easycom.test.js b/pages/component-instance/methods/call-method-easycom.test.js index 581f70bebc4aa8feb99ecf07bac5edc0ed931f3a..3447b17380f809e15dc576460452a8ef487efac9 100644 --- a/pages/component-instance/methods/call-method-easycom.test.js +++ b/pages/component-instance/methods/call-method-easycom.test.js @@ -10,6 +10,8 @@ describe('call-method-easycom', () => { const title = Date.now() + '' const result = await page.callMethod('callMethodTest', title) expect(result).toBe(title) + const customResult = await page.callMethod('callCustomMethodTest') + expect(customResult).toBe('custom foo') }) it('callMethodTest Composition API', async () => { @@ -18,5 +20,7 @@ describe('call-method-easycom', () => { const title = Date.now() + '' const result = await page.callMethod('callMethodTest', title) expect(result).toBe(title) + const customResult = await page.callMethod('callCustomMethodTest') + expect(customResult).toBe('custom foo') }) })