再会,
我对 Vue.Js 有疑问。
当我在数据库中创建新行时。我将使用 Vue.use (conctactApp) 但表格不会加载。
我需要按 CTRL + F5 来刷新捕获。然后表重新加载新数据。
当我在 localhost 上测试 Vue.js 时没有问题。
<tbody ref="contactTable" v-for="user in users" id="" >
<tr>
<td>{{ user.name }}</td>
<td>{{ user.telefon }}</td>
<td>{{ user.email }}</td>
<td>{{ user.poznamka }}</td>
<td v-on:click="editContact" :contact-poznamka="user.poznamka" :contact-email="user.email" :contact-telefon="user.telefon" :contact-name="user.name" data-toggle="modal" data-target="#editcontact" ><i class="icofont-ui-edit"></i></td>
</tr>
</tbody>
var conctactApp = new Vue({
el:"#contactList",
data () {
return {
users: []
}
},
mounted () {
console.log("Contact App Run")
axios
.get('action.php?action=load_conctacts')
.then(response => (this.users = response.data))
},
methods: {
reloadContacts(){
Vue.use(conctactApp);
},
createContact(){
let err = false;
this.$refs.ecb.value = "Create";
SetAttrById("ecb","send-type","create");
},
editContact: function(e){
this.$refs.cContactName.value = e.currentTarget.getAttribute('contact-name');
this.$refs.cContactEmail.value = e.currentTarget.getAttribute('contact-email');
this.$refs.cContactTelefon.value = e.currentTarget.getAttribute('contact-telefon');
this.$refs.cContactPoznamka.value = e.currentTarget.getAttribute('contact-poznamka');
this.$refs.ecb.value = "Save";
SetAttrById("ecb","send-type","edit");
},
saveContact:() => {
var contactData = {
name:GetInputValueById("cContactName"),
telefon:GetInputValueById("cContactTelefon"),
email:GetInputValueById("cContactEmail"),
poznamka:GetInputValueById("cContactPoznamka"),
}
console.log(contactData);
if(GetAttrById("ecb","send-type") == "create"){
axios.post("api.php",{
action:"autoinsert",
autotable:"contacts",
data: contactData,
}).then(function(response) {
console.log(response);
Vue.use(conctactApp);
});
}else if(GetAttrById("ecb","send-type") == "edit"){
alert("edit");
}
}
}
})
每次我向数据库发布新联系人时,我都需要。我的表刷新,我不必按 CTRL + F5 我尝试 forceupdate 但也不起作用
感谢所有帮助