부모 구성 요소 렌더링 방법을 알아 내고 페이지 일부의 목록에 계약 목록을 표시하고 사용자가 그 중 하나를 클릭하면 문제가 발생합니다. 특정 계약의 세부 사항을 페이지의 다른 부분에 표시하십시오.vue.js 구성 요소 렌더링 및 데이터 전달
이#contracts_area
.filter-section
ul
li.filter-item v-for="contract in contractsAry" :key="contract.id" @click="showContract(contract)"
| {{ contract.name }}
.display-section
component :is="currentView" transition="fade" transition-mode="out-in"
script type="text/x-template" id="manage-contracts-template"
div
h1 Blank when page is newly loaded for now
script type="text/x-template" id="view-contract-template"
div :apply_contract="showContract"
h1#display-item__name v-name="name"
자바 스크립트 : 사용자가 .filter 섹션의 모든 계약 항목을 클릭 할 때 있도록
기본적으로Vue.component('manage-template', {
template: '#manage-contracts-template'
});
Vue.component('view-contract', {
template: '#view-contract-template',
props: ['show_contract'],
data: function() {
return {
name: ''
}
},
methods: {
showContract: function(contract) {
return this.name = contract.name
}
}
});
Vue.http.headers.common['X-CSRF-Token'] = $('meta[name="csrf-token"]').attr('content');
var contractsResource = Vue.resource('/all_contracts{/id}.json');
var contracts = new Vue({
el: '#contracts_area',
data: {
currentView: 'manage-template',
contractsAry: [],
errors: {}
},
mounted: function() {
var that = this;
contractsResource.get().then(
function(res) {
that.contractsAry = res.data;
}
)
},
methods: {
showContract: function(contract) {
this.currentView = 'view-contract'
}
}
});
내가 그것을 그것을 싶습니다 여기
내 슬림 파일입니다 .display-section에서 해당 계약의 데이터를 보여줍니다. 이것을 어떻게 할 수 있습니까?
완벽한, 고맙습니다. 그리고 Vue를 시작하면서 심오한 답변, 거대한 도움을 주셔서 감사합니다. – asalgan