demo.vue 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. <template>
  2. <div class="demo">
  3. <h2>基本用法</h2>
  4. <nut-rate v-model="state.val" />
  5. <h2>半星</h2>
  6. <nut-rate allow-half v-model="state.val1"></nut-rate>
  7. <h2>自定义 icon </h2>
  8. <nut-rate
  9. checked-icon="heart-fill1"
  10. unchecked-icon="heart"
  11. v-model="state.val2"
  12. ></nut-rate>
  13. <h2>自定义数量</h2>
  14. <nut-rate :count="6" v-model="state.val3"></nut-rate>
  15. <h2>自定义颜色</h2>
  16. <nut-rate active-color="#FFC800" v-model="state.val4"></nut-rate>
  17. <h2>禁用状态</h2>
  18. <nut-rate disabled v-model="state.val5"></nut-rate>
  19. <h2>只读状态</h2>
  20. <nut-rate v-model="state.val6" readonly></nut-rate>
  21. <h2>绑定事件</h2>
  22. <nut-rate v-model="state.val7" @change="onChange"></nut-rate>
  23. <h2>自定义尺寸 35px</h2>
  24. <nut-rate v-model="state.val8" icon-size="35"></nut-rate>
  25. </div>
  26. </template>
  27. <script>
  28. import { reactive, getCurrentInstance } from 'vue';
  29. import { createComponent } from '@/utils/create';
  30. const { createDemo } = createComponent('rate');
  31. export default createDemo({
  32. setup() {
  33. let { proxy } = getCurrentInstance();
  34. const state = reactive({
  35. val: 3,
  36. val1: 3.5,
  37. val2: 3,
  38. val3: 3,
  39. val4: 3,
  40. val5: 3,
  41. val6: 3,
  42. val7: 3,
  43. val8: 3
  44. });
  45. const onChange = val => {
  46. proxy.$toast.text(state.result);
  47. };
  48. return {
  49. state,
  50. onChange
  51. };
  52. }
  53. });
  54. </script>
  55. <style lang="scss" scoped></style>