u-radio-group.js 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. "use strict";
  2. const common_vendor = require("../../../../common/vendor.js");
  3. const _sfc_main = {
  4. name: "u-radio-group",
  5. mixins: [common_vendor.mpMixin, common_vendor.mixin, common_vendor.props$17],
  6. computed: {
  7. // 这里computed的变量,都是子组件u-radio需要用到的,由于头条小程序的兼容性差异,子组件无法实时监听父组件参数的变化
  8. // 所以需要手动通知子组件,这里返回一个parentData变量,供watch监听,在其中去通知每一个子组件重新从父组件(u-radio-group)
  9. // 拉取父组件新的变化后的参数
  10. parentData() {
  11. return [
  12. this.modelValue,
  13. this.disabled,
  14. this.inactiveColor,
  15. this.activeColor,
  16. this.size,
  17. this.labelDisabled,
  18. this.shape,
  19. this.iconSize,
  20. this.borderBottom,
  21. this.placement
  22. ];
  23. },
  24. bemClass() {
  25. return this.bem("radio-group", ["placement"]);
  26. }
  27. },
  28. watch: {
  29. // 当父组件需要子组件需要共享的参数发生了变化,手动通知子组件
  30. parentData() {
  31. if (this.children.length) {
  32. this.children.map((child) => {
  33. typeof child.init === "function" && child.init();
  34. });
  35. }
  36. }
  37. },
  38. data() {
  39. return {};
  40. },
  41. created() {
  42. this.children = [];
  43. },
  44. emits: ["update:modelValue", "change"],
  45. methods: {
  46. // 将其他的radio设置为未选中的状态
  47. unCheckedOther(childInstance) {
  48. this.children.map((child) => {
  49. if (childInstance !== child) {
  50. child.checked = false;
  51. }
  52. });
  53. const {
  54. name
  55. } = childInstance;
  56. this.$emit("update:modelValue", name);
  57. this.$emit("change", name);
  58. }
  59. }
  60. };
  61. function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
  62. return {
  63. a: common_vendor.n($options.bemClass)
  64. };
  65. }
  66. const Component = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["render", _sfc_render], ["__scopeId", "data-v-272bb654"], ["__file", "D:/project/学吧/learn_applet/node_modules/uview-plus/components/u-radio-group/u-radio-group.vue"]]);
  67. wx.createComponent(Component);