Ich versuche, ein modales Pop-up mit Details einer Kreditkarte zu haben. Die Details stammen aus einer AJAX-Anfrage. Aus irgendeinem Grund wird die Root-Vue-Instanz aktualisiert, die Komponenteninstanz jedoch nicht. Dies ist, was ich zur Zeit haben -Vue JS AJAX Anruf innerhalb Modal
HTML:
<!-- View Card Details Modal -->
<!-- Modal -->
<div class="modal fade" id="ccdetails" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<h4 class="modal-title" id="myModalLabel">View Card Details</h4>
</div>
<card-details cardid="{{$cc->card_id}}" :message="getCCDetails('{{$cc->card_id}}')"></card-details>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
<!-- <button type="button" class="btn btn-primary">Save changes</button> -->
</div>
</div>
</div>
</div>
Vue JS:
<script type="text/javascript">
Vue.component('card-details', {
template: '<div class="modal-body">@{{message}}</div>',
// data is technically a function, so Vue won't
// complain, but we return the same object
// reference for each component instance
props: ['message', 'cardid']
}),
new Vue({
el: '#ccdetails',
data: {
cardid: '',
message: ''
},
methods: {
getCCDetails: function (id) {
console.log(id)
console.log('calling function')
axios.get('/card/'.concat(id))
.then(function (response) {
this.message = JSON.stringify(response.data)
}.bind(this))
.catch(function (error) {
return this.message = 'Sorry there was an error'
}.bind(this));
}
}
})
</script>
Für die Ausgabe, Wurzel-Instanz hat cardid = undefined
und message = the output
ich will. Meine cardDetails-Instanz hat den Wert cardid
korrekt, aber message = undefined
.
Welche Version von Vue ist das? Und was genau ist $ cc variabel? – Staszek
Es ist ein wenig verwirrend. Sie müssen ein Beispiel für Ihre $ cc hinzufügen. In einem Kommentar unten hast du behauptet, dass es mehrere $ cc geben kann - daher würde ich sagen, dass du nirgendwo hinschlingst. Haben Sie sichergestellt, dass $ cc-> card_id nicht null ist? –