有一個組件“TableFields.vue”和兩個視圖文件“Home.vue”。和“Statistics.vue”。在組件中,我在 對象下有 changes: [] 變量。data() data () { return { startStopA: true, startStopB: true, initialValueA: 3, initialValueB: 3, randomNumbersArray: [], randomSignA: '+', randomSignB: '+', signsArray: ['+', '-'], intervalA: null, intervalB: null, changes: [] } },該changes數(shù)組從calculationsA()函數(shù)動態(tài)獲取對象。 calculationsA () { this.randomSignA = this.signsArray[ Math.floor(Math.random() * this.signsArray.length) ] this.randomSignA === '+' ? (this.initialValueA += this.randomNumbersArray[0]) : (this.initialValueA -= this.randomNumbersArray[0]) const d = new Date() // console.log(d.toLocaleTimeString()) // console.log(this.randomNumbersArray[0]) // this.changes.push(this.randomNumbersArray[0]) // this.changes.push(d.toLocaleTimeString()) // console.log(this.changes) const newChange = {} newChange.field = 'A' newChange.value = this.randomNumbersArray[0] newChange.time = d.toLocaleTimeString() this.changes.push(newChange) },如何將 changes: [] 從 TableField.vue 組件傳遞到 Statistics.vue 頁面,以便使用 編寫動態(tài)表格a> 中看到。 組件的工作代碼,可以從根 url changes 數(shù)組對象數(shù)據(jù)。我不確定,我是否需要創(chuàng)建新組件,或者沒有它也可以完成?;旧?,這是出于測試目的而實現(xiàn)的 TableField.vueHome.vue <div class="statistics"> <table> <tr> <th>Field</th> <th>Value</th> <th>Time</th> </tr> <tr v-for="item in changes" :key="item.value"> <td>{{ item.field }}</td> <td>{{ item.value }}</td> <td>{{ item.time }}</td> </tr> </table> </div> </div>我需要該代碼才能在 Statistics.vue 頁面上運行。為了更加方便,這里是 鏈接 gitlab 存儲庫。
從組件獲取數(shù)據(jù)到另一個頁面視圖
幕布斯6054654
2023-12-19 16:16:40