<template>
  <div>
    <slot v-bind="{that}" />
    <!-- 示例
    <StringToArray v-model="formdata.prop">
      <template v-slot="scope">
        <el-select v-model="scope.that.model" multiple>
          <el-option
            v-for="option in options"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          />
        </el-select>
      </template>
    </StringToArray>
    -->
  </div>
</template>

<script>
export default {
  name: 'StringToArray',
  props: {
    value: {
      type: String,
      default: () => {
        return ''
      }
    },
    splitChar: {
      type: String,
      default: () => {
        return ','
      }
    }
  },
  computed: {
    model: {
      set(value) {
        this.$emit('input', value.join(this.splitChar))
      },
      get() {
        return this.value ? this.value.split(this.splitChar) : []
      }
    },
    that() {
      return this
    }
  }
}
</script>
