فهرست منبع

fix(runtime-vapor): remove v-cloak and add data-v-app after app mount (#14035)

edison 5 ماه پیش
والد
کامیت
172cb8b1a1
2فایلهای تغییر یافته به همراه23 افزوده شده و 1 حذف شده
  1. 17 0
      packages/runtime-vapor/__tests__/directives/vCloak.spec.ts
  2. 6 1
      packages/runtime-vapor/src/apiCreateApp.ts

+ 17 - 0
packages/runtime-vapor/__tests__/directives/vCloak.spec.ts

@@ -0,0 +1,17 @@
+import { createVaporApp, template } from '../../src'
+
+describe('vCloak', () => {
+  test('should be removed after mount', () => {
+    const root = document.createElement('div')
+    root.setAttribute('v-cloak', '')
+    createVaporApp({
+      setup() {
+        expect(root.hasAttribute('v-cloak')).toBe(true)
+        expect(root.hasAttribute('data-v-app')).toBe(false)
+        return template(`<div></div>`)()
+      },
+    }).mount(root)
+    expect(root.hasAttribute('v-cloak')).toBe(false)
+    expect(root.hasAttribute('data-v-app')).toBe(true)
+  })
+})

+ 6 - 1
packages/runtime-vapor/src/apiCreateApp.ts

@@ -94,7 +94,12 @@ function postPrepareApp(app: App) {
   const mount = app.mount
   app.mount = (container, ...args: any[]) => {
     container = normalizeContainer(container) as ParentNode
-    return mount(container, ...args)
+    const proxy = mount(container, ...args)
+    if (container instanceof Element) {
+      container.removeAttribute('v-cloak')
+      container.setAttribute('data-v-app', '')
+    }
+    return proxy
   }
 }