TextTag.js 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. let TextTag = `<div :style="text?'display:inline-block;':''">
  2. <template v-for="(item, i) in options">
  3. <template v-if="column === null">
  4. <template v-if="values.includes(String(item))">
  5. <span v-if="text">{{ item }}</span>
  6. <el-tag v-else>{{ item }}</el-tag>
  7. </template>
  8. </template>
  9. <template v-else>
  10. <template v-if="values.includes(String(item[column]))">
  11. <template v-if="label === null">
  12. <span v-if="text">{{ item }}</span>
  13. <el-tag v-else>{{ item }}</el-tag>
  14. </template>
  15. <template v-else>
  16. <span v-if="text">{{ item[label] }}</span>
  17. <el-tag v-else>{{ item[label] }}</el-tag>
  18. </template>
  19. </template>
  20. </template>
  21. </template>
  22. </div>`;
  23. Vue.component('my-texttag', {
  24. template: TextTag,
  25. props: {
  26. options: {
  27. type: Array,
  28. default: null,
  29. },
  30. // 指定列
  31. column: {
  32. type: [String],
  33. default: null,
  34. },
  35. // 指定文本
  36. label: {
  37. type: [String],
  38. default: null,
  39. },
  40. // 当前的值
  41. value: [Number, String, Array],
  42. // 文本显示
  43. text: {
  44. type: [Boolean],
  45. default: false,
  46. }
  47. },
  48. computed: {
  49. values: function(){
  50. if (this.value !== null && typeof this.value !== "undefined") {
  51. return Array.isArray(this.value) ? this.value : [String(this.value)];
  52. } else {
  53. return [];
  54. }
  55. }
  56. },
  57. data: function() {
  58. return {
  59. }
  60. },
  61. created:function(){
  62. _this = this;
  63. },
  64. methods:{
  65. }
  66. })