wolyshaw 4 yıl önce
ebeveyn
işleme
099c3596b9
1 değiştirilmiş dosya ile 19 ekleme ve 8 silme
  1. 19 8
      src/components/copy-text/index.vue

+ 19 - 8
src/components/copy-text/index.vue

@@ -1,7 +1,7 @@
 <template>
-  <span class="copy" v-if="textContent">
+  <span class="copy" v-if="content">
     <slot/>{{text}}
-    <i v-if="!!textContent" @click="copyText" title="复制" class="el-icon-document-copy"></i>
+    <i v-if="!!content" @click="copyText" title="复制" class="el-icon-document-copy"></i>
   </span>
 </template>
 
@@ -20,16 +20,27 @@ export default {
       default: true
     }
   },
-  computed: {
-    textContent() {
-      const slot = this.$slots.default || []
-      const text = slot[0]?.text || this.text
-      return text
+  data() {
+    return {
+      content: ''
     }
   },
+  mounted() {
+    this.getTextContent()
+  },
+  updated() {
+    console.log('gengxin ')
+    this.getTextContent()
+  },
   methods: {
+    getTextContent() {
+      const slot = this.$slots.default || []
+      const text = slot[0]?.text || this.text
+      this.content = text
+      return text
+    },
     copyText() {
-      const text = this.textContent
+      const text = this.content
       if (text) {
         copy(text)
         if (this.hint) {