The setup binding property "nowFirst" is already declared. found in
时间: 2024-11-09 20:24:17 浏览: 28
In the provided document, the setup binding property `nowFirst` is indeed declared more than once, which can cause issues in the Vue application. Here are the specific instances where it is declared:
1. **Initial Declaration:**
```javascript
const state = reactive({
nowFirst: 'projectCode',
// other properties...
});
```
2. **Redundant Declaration:**
```javascript
const departChange = (val) => {
if (val == 2) {
nowFirst.value = 'orgCode_dictText';
// other logic...
} else {
nowFirst.value = 'projectCode';
// other logic...
}
columnsKey.value += 1;
};
```
### Solution
To resolve this issue, you should ensure that `nowFirst` is only declared once in the `state` object. The `departChange` function can then modify the `nowFirst` property as needed without redeclaring it.
Here is the corrected version of the relevant parts of the code:
1. **State Initialization:**
```javascript
const state = reactive({
nowFirst: 'projectCode',
columnsKey: 0,
projectNameList: [],
projectName_Code: '',
projectBudgetMarginWarning: 0,
expandedRowKeys: [],
workorderProjectList: [],
description: '营业报表管理页面',
fastTime: ['本月', '上月', '近半年'],
noCreate: true,
hasUpdateTime: true,
configOrderSubTypeList: [],
configOrderSubTypeTemp: undefined,
allDepartList: [],
hallCodeDataList: [],
spinning: false,
checkFlag: true,
updateTime: '',
url: {
list: "/web/materialVoucherDetails/getProjectMaterialStatistic",
exportXlsxUrl: "/web/materialVoucherDetails/exportProjectMaterialStatisticExcel",
exportPdfUrl: "/web/bizBusinessRecord/exportpdf",
exportDetailUrl: "/web/bizBusinessRecord/exportDetailExcel"
},
keyList: ['saleNum', 'saleName', 'terminalTypeName', 'userTypeName', 'configOrderMainTypeName', 'configOrderSubTypeName'],
ipagination: {
current: 1,
pageSize: 20,
pageSizeOptions: ['20', '50', '80'],
showTotal: (total, range) => `${range[0]}-${range[1]} 共 ${total} 条`,
showQuickJumper: true,
showSizeChanger: true,
total: 0
},
originColums: [],
columns: [
// column definitions...
],
queryParam: {
type: '',
projectCode: '',
projectName: '',
projectName_Code: "",
subProjectName: '',
departId: '',
material: '',
producerId: '',
specification: '',
materialInventoryResult: '',
projectDateBegin: '',
projectDateEnd: ''
},
dataSource: [],
loading: false,
toggleSearchStatus: false
});
```
2. **Function to Change `nowFirst`:**
```javascript
const departChange = (val) => {
if (val == 2) {
state.nowFirst = 'orgCode_dictText';
let objectArray = deepClone(state.originColums);
let movedElement = objectArray.splice(3, 1)[0];
objectArray.unshift(movedElement);
state.columns = objectArray;
} else {
state.nowFirst = 'projectCode';
state.columns = deepClone(state.originColums);
}
state.columnsKey += 1;
};
```
By making these changes, you ensure that `nowFirst` is only declared once and can be modified as needed within the `departChange` function. This will prevent any potential conflicts or errors in your Vue application.
阅读全文