const app = new Vue(
{
el: '#app',
data:
{
corrs: []
},
mounted: function(){
this.getAllCorrs();
},
methods: {
getAllCorrs() {
axios.get("http://url.local/api.php?action=read")
.then(response => {
app.corrs = response.data
})
.catch(error => {
console.log('-----error-------');
console.log(error);
})
}
});
<tr v-for="corr in corrs">
<th>{{corr.id}}</th>
<td>{{corr.name}}</td>
<td>{{corr.fivest}}</td>
<td>{{corr.comment}}</td>
</tr>
import Vue from 'vue'
import App from './App'
const app = new Vue({
el: '#app',
template: '<App/>',
components: { App }
})
<template>
<div>
<tr v-for="corr in corrs" :key="corr.id">
<th>{{corr.id}}</th>
<td>{{corr.name}}</td>
<td>{{corr.fivest}}</td>
<td>{{corr.comment}}</td>
</tr>
</div>
</template>
<script>
import axios from 'axios'
export default {
data () {
return {
corrs: []
}
},
created () {
this.getAllCorrs()
},
methods: {
getAllCorrs () {
axios.get("http://url.local/api.php?action=read").then(response => {
this.corrs = response.data
}).catch(error => {
console.log('-----error-------')
console.log(error)
})
}
}
}
</script>
<div id="app"></div>
<script src="/js/my.js"></script>
getAllCorrs() {
// добавляем
const self = this;
axios.get("http://url.local/api.php?action=read")
.then(response => {
//app.corrs = response.data
// и здесь обращаемся не к this а к self
self.corrs = response.data
})