index.vue 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. <template>
  2. <demo-section>
  3. <demo-block :title="$t('alert1')">
  4. <van-button
  5. type="primary"
  6. plain
  7. @click="onClickAlert"
  8. >
  9. {{ $t('alert1') }}
  10. </van-button>
  11. <van-button
  12. type="primary"
  13. plain
  14. @click="onClickAlert2"
  15. >
  16. {{ $t('alert2') }}
  17. </van-button>
  18. </demo-block>
  19. <demo-block :title="$t('confirm')">
  20. <van-button
  21. type="primary"
  22. plain
  23. @click="onClickConfirm"
  24. >
  25. {{ $t('confirm') }}
  26. </van-button>
  27. </demo-block>
  28. <demo-block :title="$t('asyncClose')">
  29. <van-button
  30. type="primary"
  31. plain
  32. @click="onClickAsyncClose"
  33. >
  34. {{ $t('asyncClose') }}
  35. </van-button>
  36. </demo-block>
  37. <demo-block :title="$t('componentCall')">
  38. <van-button
  39. type="danger"
  40. plain
  41. @click="show = true"
  42. >
  43. {{ $t('componentCall') }}
  44. </van-button>
  45. <van-dialog
  46. v-model="show"
  47. :title="$t('title')"
  48. show-cancel-button
  49. :lazy-render="false"
  50. >
  51. <img :src="image">
  52. </van-dialog>
  53. </demo-block>
  54. </demo-section>
  55. </template>
  56. <script>
  57. export default {
  58. i18n: {
  59. 'zh-CN': {
  60. alert1: '提示弹窗',
  61. alert2: '提示弹窗(无标题)',
  62. confirm: '确认弹窗',
  63. asyncClose: '异步关闭',
  64. componentCall: '组件调用',
  65. content: '代码是写出来给人看的,附带能在机器上运行'
  66. },
  67. 'en-US': {
  68. alert1: 'Alert',
  69. alert2: 'Alert without title',
  70. confirm: 'Confirm dialog',
  71. asyncClose: 'Async Close',
  72. componentCall: 'Component Call',
  73. }
  74. },
  75. data() {
  76. return {
  77. show: false,
  78. currentRate: 0,
  79. image: 'https://img.yzcdn.cn/public_files/2017/09/05/4e3ea0898b1c2c416eec8c11c5360833.jpg'
  80. };
  81. },
  82. methods: {
  83. onClickAlert() {
  84. this.$dialog.alert({
  85. title: this.$t('title'),
  86. message: this.$t('content')
  87. });
  88. },
  89. onClickAlert2() {
  90. this.$dialog.alert({
  91. message: this.$t('content')
  92. });
  93. },
  94. onClickConfirm() {
  95. this.$dialog.confirm({
  96. title: this.$t('title'),
  97. message: this.$t('content')
  98. });
  99. },
  100. onClickAsyncClose() {
  101. function beforeClose(action, done) {
  102. if (action === 'confirm') {
  103. setTimeout(done, 1000);
  104. } else {
  105. done();
  106. }
  107. }
  108. this.$dialog.confirm({
  109. title: this.$t('title'),
  110. message: this.$t('content'),
  111. beforeClose
  112. });
  113. }
  114. }
  115. };
  116. </script>
  117. <style lang="less">
  118. .demo-dialog {
  119. .van-doc-demo-block > .van-button {
  120. margin-left: 15px;
  121. }
  122. img {
  123. width: 100%;
  124. padding: 25px 20px 0;
  125. box-sizing: border-box;
  126. }
  127. }
  128. </style>