1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
  | 
diff --git a/src/extension.ts b/src/extension.ts
index 0e7d70b9c319b92521ed2e4100c03d73653bde39..e79a732b0b2ff6c84357a2db93f90e85e4e3699b 100644
--- a/src/extension.ts
+++ b/src/extension.ts
@@ -499,15 +499,7 @@       createCompletionItemProvider({
         items: this._items,
         languages: ['vue'],
         regex: /\bclass=["']([^"']*)$/,
-        enable: text => {
-          if (
-            text.indexOf('<template') !== -1 &&
-            text.indexOf('</template>') === -1
-          ) {
-            return true
-          }
-          return false
-        },
+        enable: isWithinTemplate,
         triggerCharacters: ["'", '"', ' ', separator]
           .concat([
             Object.keys(
@@ -788,3 +780,13 @@     },
     ' '
   )
 }
+
+function isWithinTemplate(text: string) {
+  let regex = /(<\/?template\b)/g
+  let match
+  let d = 0
+  while ((match = regex.exec(text)) !== null) {
+    d += match[0] === '</template' ? -1 : 1
+  }
+  return d !== 0
+}
  |