12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576 |
- Component({
- options: {
- multipleSlots: true // 在组件定义时的选项中启用多slot支持
- },
- relations: {
- '../grid-item/index': {
- type: 'child',
- linked(target) {
- this.initGrids();
- },
- unlinked(target) {
- this.initGrids();
- }
- },
- },
- externalClasses: ['l-class', 'l-class-grid'],
- properties: {
- rowNum: {
- type: String,
- value: 3,
- },
- showBorder: Boolean,
- showColBorder: Boolean,
- showRowBorder: Boolean,
- },
- data: {
- gridItems: [],
- childNum: 0,
- currentIndex:null,
- },
- ready() {
- this.initGrids();
- },
- lifetimes: {
- show() {
- },
- },
- methods: {
- initGrids() {
- let items = this.getRelationNodes('../grid-item/index');
- if (this.data.childNum === items.length) return;
- const gridItems = items.map((item) => {
- return {
- key: item.data.key
- }
- });
- this.setData({
- gridItems: gridItems,
- childNum: items.length
- })
- },
- tapGridItem(e) {
- const {
- index
- } = e.currentTarget.dataset;
- this.setData({
- currentIndex:index
- });
- let items = this.getRelationNodes('../grid-item/index');
- items[index].tapGridItem({
- index: index
- });
- },
- tapGrid(e) {
- this.triggerEvent('lintap', {
- index:this.data.currentIndex
- })
- }
- }
- });
|