demo.vue 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. <template>
  2. <div class="demo full">
  3. <h2>基础用法</h2>
  4. <nut-cell @click="switchActionSheet('dialogShow')">点击出现输出框</nut-cell>
  5. <nut-cell>您输入的密码是:{{ state.value }}</nut-cell>
  6. <h2>展示按钮</h2>
  7. <nut-cell @click="switchActionSheet('dialogShow1')"
  8. >点击出现输出框</nut-cell
  9. >
  10. <nut-cell>您输入的密码是:{{ state.value1 }}</nut-cell>
  11. <nut-shortpassword
  12. v-model:value="state.value"
  13. v-model:is-visible="state.dialogShow"
  14. :show-button="true"
  15. >
  16. </nut-shortpassword>
  17. <nut-shortpassword
  18. v-model:value="state.value1"
  19. v-model:is-visible="state.dialogShow1"
  20. :show-button="false"
  21. >
  22. </nut-shortpassword>
  23. </div>
  24. </template>
  25. <script lang="ts">
  26. import { ref, reactive, toRefs, watch } from 'vue';
  27. import { createComponent } from '@/utils/create';
  28. const { createDemo } = createComponent('shortpassword');
  29. export default createDemo({
  30. setup() {
  31. const state = reactive({
  32. dialogShow: false,
  33. dialogShow1: false,
  34. value: '',
  35. value1: ''
  36. });
  37. // 方法
  38. function switchActionSheet(param) {
  39. state[`${param}`] = !state[`${param}`];
  40. }
  41. watch(
  42. () => state.value,
  43. val => {
  44. if (val.length == 6) {
  45. state.dialogShow = false;
  46. console.log(state.dialogShow);
  47. }
  48. }
  49. );
  50. return {
  51. state,
  52. switchActionSheet
  53. };
  54. }
  55. });
  56. </script>
  57. <style lang="scss" scoped></style>