index.vue 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. <template>
  2. <div class="qrCode">
  3. <el-dialog :title="title"
  4. :visible.sync="status"
  5. @close="onDialogClose"
  6. width="300px">
  7. <div class="left-code">
  8. <vue-qr :text="codeUrl" style="width: 100%" :margin="0"></vue-qr>
  9. <p class="code-url" v-if="codeUrl">{{ codeUrl }} <el-link @click="copyUrl(codeUrl)" class="link-btn" type="primary">复制</el-link></p>
  10. </div>
  11. </el-dialog>
  12. </div>
  13. </template>
  14. <script>
  15. import VueQr from 'vue-qr'
  16. import copy from 'copy-to-clipboard'
  17. export default {
  18. data() {
  19. return {
  20. status: false
  21. };
  22. },
  23. components: {
  24. VueQr
  25. },
  26. props: {
  27. value: {
  28. // 组件状态
  29. type: Boolean,
  30. required: true,
  31. default() {
  32. return false
  33. }
  34. },
  35. title: {
  36. type: String,
  37. default() {
  38. return '查看二维码'
  39. }
  40. },
  41. codeUrl: {
  42. type: String
  43. }
  44. },
  45. mounted() {
  46. this.status = this.value
  47. },
  48. methods: {
  49. onDialogClose() {
  50. this.status = false
  51. this.$emit('input', false)
  52. },
  53. copyUrl(url) {
  54. copy(url)
  55. this.$message.success('复制成功')
  56. },
  57. },
  58. watch: {
  59. value(newValue) {
  60. this.status = newValue;
  61. },
  62. title(newValue, oldValue) {
  63. if(newValue != oldValue) {
  64. this.title = newValue
  65. }
  66. }
  67. },
  68. beforeDestroy() {},
  69. };
  70. </script>
  71. <style lang="scss">
  72. .left-code{
  73. .code-url{
  74. margin-top: 10px;
  75. margin-bottom: 10px;
  76. .link-btn{
  77. margin-top: 0;
  78. margin-bottom: 0;
  79. font-size: 12px;
  80. }
  81. }
  82. }
  83. </style>