尝试做一个简单的输入框。默认值应该是数据库值,当用户更新该值时,它还会更新数据库。我正在使用Laravel 5.5,这是一个vue组件。因此,数据库中的初始值为3,但如果有人更改了值,则还会更新数据库。我是在正确的轨道上,有什么在下面,还是我离开了?目前它不会获得初始金额,也不会更新。
Route::post('/corn', function () {
$test = App\Resource::where('user_id', Auth::id())->update(['cornquant' => request('amount')]);
return $test;
});
这是路线(做了一点编辑,现在更新):
import vtk_visualizer as vv
import numpy as np
import sys
from PyQt5.QtWidgets import *
xyz = np.random.rand(1000, 3)
vtkControl = vv.VTKVisualizerControl()
vtkControl.AddPointCloudActor(xyz)
app = QApplication.instance()
if app is None:
app = QApplication(sys.argv)
app.exec_()
答案 0 :(得分:0)
在去抖动中使用es6箭头功能来保留$ImageUrl = "http://www.example.com/media/image1.png";
$localPath = "media/logos/" . md5(uniqid());
file_put_contents($localPath, file_get_contents($ImageUrl));
。然后移除this
并分配给var vm = this
等玉米。
你最初在哪里打电话this.corn = response.data
?
答案 1 :(得分:0)
让一切都排序。定义默认值是最难的部分,但最终很容易!
这是vue模板文件:
<template>
<div>Corn: <input v-model="corn" style="width: 50px;" /></div>
</template>
<script>
export default {
data: function() {
return {
items: 'not updated',
corn: '0'
} },
watch: { // whenever input amount changes, function will run
corn: function() {
this.getCorn()
} },
mounted: function() {
this.getVueItems(); //this will call the actual corn value to put as the default value
},
methods: {
getVueItems: function() {
axios.get('/testing').then(response => {
this.items = response.data;
this.corn = response.data.cornlq; //set initial value
}); },
getCorn: _.debounce(
function() {
var vm = this
axios.post('/corn', { //updates database
corn: this.corn,
}).then(response => {
vm.corn = response.data.cornlq; //keeps actual database value in input
}) },
2000
) }, }
</script>
路线:
Route::post('/corn', function () {
App\Resource::where('user_id', Auth::id())->update(['cornlq' => request('corn')]); //update database with new amount
$result = App\Resource::where('user_id', Auth::id())->first(); //save all amounts to $result
return $result; //return result so I can update the vue
});