3π
β
Yes can add field you donβt want in return
Solution 1
this.games = res.data.data.map(({
ID,
IdUser,
...rest
}) => rest);
var v1 = [
{ID: 1, Title: "dqdq", Description: "dqdq", IdUser: 3},
{ID: 2, Title: "dqdq", Description: "dqdq", IdUser: 3},
{ID: 3, Title: "dqdqddd", Description: "dqdq", IdUser: 3},
{ID: 4, Title: "dqdqddd", Description: "dqdq", IdUser: 3},
{ID: 5, Title: "dqdqddd", Description: "dqdq", IdUser: 3}]
var games = v1.map(({
ID,
IdUser, ...rest}) => rest);
console.log(games);
Solution 2
https://stackoverflow.com/a/25470077/6923146
You can use map:
this.games = res.data.data.map(obj => {
Title: obj.Title,
Description: obj.Description
});
3π
you can Try this also
<div>
<Navbar />
<gamesIdeaList :games="games" />
</div>
</template>
<script>
// @ is an alias to /src
import Navbar from '@/components/Navbar.vue'
import gamesIdeaList from '@/components/gamesIdeaList.vue'
import axios from 'axios'
export default {
name: 'home',
components: {
Navbar,
gamesIdeaList
},
data() {
return {
games:[]
}
},
// props: info,
mounted () {
axios.get('http://localhost:3001/GamesIdea', {
headers: { Authorization: `Bearer ${localStorage.usertoken}` }
})
.then(res => {
this.games = res.data.map(val => {
return {
Title: val.Title,
Description:val.Description}
})
console.log(arr)
})
.catch(error => {
console.log(error)
this.errored = true
})
}
}
</script>```
2π
Try to use map
array function as follows :
this.games = res.data.data.map(d=>{Title: d.Title,Description:d.Description});
Source:stackexchange.com