select.js 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. export default (injectName) => {
  2. return {
  3. inject: [injectName],
  4. props: {
  5. value: { type: Number, default: 1 },
  6. size: {
  7. type: String,
  8. default: 'small',
  9. validator(value) {
  10. const validSizes = ['medium', 'small', 'mini']
  11. const isValid = validSizes.includes(value) || value === ''
  12. if (!isValid) {
  13. console.warn(`Invalid prop: size should be one of 'medium', 'small', or 'mini', but received '${value}'.`)
  14. }
  15. return isValid
  16. }
  17. }
  18. },
  19. data() {
  20. return {
  21. selectValue: 1
  22. }
  23. },
  24. watch: {
  25. value: {
  26. handler(newValue, oldValue) {
  27. if (newValue !== oldValue) {
  28. this.selectValue = newValue
  29. }
  30. },
  31. immediate: true
  32. },
  33. selectValue: {
  34. handler(newValue, oldValue) {
  35. if (newValue !== oldValue) {
  36. this.$emit('input', newValue)
  37. }
  38. }
  39. }
  40. }
  41. }
  42. }