[英]How to fetch data from the DB using Vue axios in laravel?
我需要使用 controller 中的查詢從數據庫中獲取數據。
我在 vue 模板中有3 個 div 。
<div id="div1">0</div>
<div id="div2">0</div>
<div id="div3">0</div>
對於每個 div element
,值0
應替換為查詢中的 Count(*) 值。 查詢應來自 2 個表表 A 和tables
B
SELECT count(*) FROM $tableA->project WHERE $tableB->question != null;
查詢結果在 3 個表ProjectA
, ProjectB
, ProjectC
($tableA->project = ProjectA, ProjectB, ProjectC) 表ProjectA
, ProjectB
, ProjectC
有一個名為1
($tableB->question = 1 ) 的列,其中包含Values(like 1, 2,3)
不是EMPTY 值。 所有非空值的總數應該是查詢的結果。
例如,表項目 A 具有如下所示的列
項目A
1 (COLUMN)
EMPTY
EMPTY
EMPTY
1
2
EMPTY
項目 B
1 (COLUMN)
EMPTY
EMPTY
EMPTY
1
2
EMPTY
每個 Div 中的0
應替換為值的計數(在表中的 col 1
中,這里的總計數為 2(1,2))
export default {
data: function() {
return {
actualValue:'',
query: ''
}
},
mounted() {
this.updateValue()
},
updateValue: function() {
axios.get('/api/updatedcount/',{
query: this.query
}).then((response) => {
this.actualValue = response.data;
console.log(this.actualValue);
})
.catch(function (error) {
console.log(error);
});
}
Route::get('/updatedcount', 'someController@someMethod');
如何編寫 controller 代碼以從 Query 中fetch the count(*)
並將其綁定到div
? 有人可以幫忙嗎
謝謝
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.