123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103 |
- 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
- },
- },
- }
|