这是我在JSFiddle上的代码。 https://jsfiddle.net/irfandyjip89/eywraw8t/440190/
window.onload = function() {
var app = new Vue({
el: "#app",
data: {
toWorkOrder: "",
workorder: {
data: [{
no_workorder: 1234,
job: 'Testing'
}, {
no_workorder: 2345,
job: 'Survey'
}],
filter: null,
fields: {
no_workorder: {
label: 'No',
sortable: true
},
job: {
label: 'Job Type'
},
details: {
label: "Action"
}
}
}
},
methods: {
getNoWO(wo) {
detailString = "localhost/work-order-details.php?no_wo=" + wo;
alert(detailString);
return this.toWorkOrder = detailString;
}
}
})
}
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.0/css/bootstrap.min.css" rel="stylesheet" />
<link href="https://unpkg.com/bootstrap-vue@latest/dist/bootstrap-vue.css" rel="stylesheet" />
<div id="app" class="mx-3 my-3">
<b-table hover small bordered :items='workorder.data' :filter='workorder.filter' :fields='workorder.fields'>
<div slot="details" slot-scope='work'>
<a target="_blank" :href="toWorkOrder">
<b-button variant="dark" class="px-1 py-1" @click='getNoWO(work.item.no_workorder)'>
Details
</b-button>
</a> {{work.item.no_workorder}}
</div>
</b-table>
<!-- So here's the actual problem, it seems that the element a, goes first, without the link given in "toWorkOrder", so it overlaps. However I had no idea how to make a wait for toWorkOrder loads first! -->
{{toWorkOrder}}
</div>
<script src="https://cdn.jsdelivr.net/npm/vue@2.5.17/dist/vue.min.js"></script>
<script src="https://unpkg.com/bootstrap-vue@latest/dist/bootstrap-vue.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.0/js/bootstrap.min.js"></script>
并转到指导页面work-order-details.php
var_dump($_GET);
我想做什么
getNoWO
并获取所选no_wo
的变量getNoWO
影响toWorkOrder
的值,该值通过a
绑定到:href
no_wo
。实际发生的事情
所以..
首次点击:打开同一页面。 第二次点击:获取“首次点击”价值。 第三次点击:获取第二次点击的价值。
这很奇怪,因为当我单击第一次单击时,警报会说出我单击的项目的确切值,然后是第二个,依此类推。但是我却改为发送到其他页面。可以询问更多信息。
PS 。我发现了问题,您也可以在JSFiddle上阅读它。似乎a
元素与函数重叠,因此a
首先没有toWorkOrder
中给出的链接。所以,新问题。如何使a
等待toWorkOrder
直到加载?