export default { props: { dataVal: { type: Object | String, default: null }, attrs: { type: Object | String, default: null }, styles: { type: Object | String, default: null }, }, data() { return { dataMessage: 'network request', dataLists: [], }; }, methods: { setInit(data) { if (data instanceof Array) { this.dataLists = data.map(el => { const obj = {} for (let key in el) { obj[key] = el[key].value if (key === 'image' && !obj.image) { obj.image = '/' } } return obj }) return } if (data instanceof Object) { const { dataList } = data; if (dataList) { this.setInit(dataList) return false } } this.dataLists = data } }, computed: { // mOptions() { // return { // ...this.defaultOptions, // ...this.options // } // } }, watch: { dataVal: { handler(newValue, oldValue) { if (newValue) { if (newValue.dataMsg) { const { dataMsg } = newValue; if (dataMsg.dataList === this.dataMessage) { const oldDataList = oldValue ? oldValue.dataMsg.dataList : null try { dataMsg.dataList !== oldDataList ? this.onNetworkRequest() : '' } catch (e) { //TODO handle the exception console.error('当前组件onNetworkRequest方法错误:' + e.message) } } else { try { this.setInit(dataMsg) } catch (e) { //TODO handle the exception } } } else { console.log('newValue = ', newValue) try { this.setInit(newValue.dataList) } catch (e) { //TODO handle the exception } } } }, deep: true, immediate: true }, }, }