1.0.3 • Published 3 years ago

sub-components v1.0.3

Weekly downloads
-
License
MIT
Repository
-
Last release
3 years ago

sub-components

类似于Vue中component的理念。渲染一个“元组件”为动态组件。根据传入 com 的值,来决定哪个组件被渲染。

区别点在于sub-components支持不定层级的“元组件”的渲染。

用法示例

  1. npm install sub-components
  2. 在页面中引用sub-components和元组件(以Tabs组件为例)
import SubComponents from "sub-components";
import Tabs from "./components/tabs";
export default {
  components: {
    SubComponents,
    Tabs,
  },
  1. 在html中使用该组件,com中传入元组件的名称
<sub-components
  com="Tabs"
  :dataList="tabData"
  transferLevel
  @switchTab="switchTab"
>
  <p>{{ content }}</p>
</sub-components>
<script>
export default {
  // ...
  data() {
    return {
      tabData: [
        [1, 2, 3],
        [1, 2],
        [1, 2, 3, 4]
      ],
      path: [0, 0, 0],
    };
  },
  computed: {
    content: function() {
      return 'content' + this.path.reduce((acc, cur) => acc + '-' + (cur + 1), '');
    },
  },
  methods: {
    switchTab(data) {
      const { level, index } = data;
      this.$set(this.path, level, index);
    },
  },
}
</script>
  1. 效果展示

npm.io

属性

Attributes

参数说明类型默认值必选
com元组件的名称string必选
dataType元组件的属性名string"data"
dataList元组件的数据列表array | number1必选
range层级(min, max)arraythis.dataList.length, this.dataList.length
transferLevel是否传递层级索引level到组件propsbooleanfalse
config具体配置Object{}

slots

Name说明scoped
-自定义内容(default)-
levelControl层级控制(index 当前层级索引;increase 可增大;decrease 可减小){index: number,increase: boolean,decrease: boolean}

本地开发

  • git clone https://github.com/xichi/vue-sub-components
  • npm install
  • npm run dev
1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago

1.0.3

3 years ago

0.0.1

3 years ago