【发布时间】:2018-07-13 19:28:43
【问题描述】:
我是 Vue.js 的新手。问题是我无法用 JSON 的值填充表格。控制台显示:
属性或方法“表”未定义
当我点击按钮时,它会说:
未定义属性或方法“allRecords”
我不知道为什么。会不会是 index.js 的问题,还是下面代码的问题?
谢谢
<template>
<div >
<input type='button' @click='allRecords()' value='Select All users'>
<b-table striped hover responsive id="tabla_final" >
<tr v-for='table in tables'>
<td>{{ table.sum_real }}</td>
<td>{{ table.sum_ppto }}</td>
<td>{{ table.sum_real }}</td>
</tr>
</b-table>
</div>
</template>
<script>
import Vue from 'vue'
const axios = require('axios')
window.onLoad = function () {
var app = new Vue({
el: '#tabla_final',
data: {
tables: ''
},
methods: {
allRecords: function () {
axios.get('http://localhost/Tribeca/api.php')
.then(function (response) {
app.tablas = response.data
console.log(response.data)
})
.catch(function (error) {
console.log(error)
})
}
}
})
}
</script>
【问题讨论】:
-
我很好奇,你为什么用
window.onLoad = function () { ...,?这似乎没有必要。