मैं ऐप से घटक तक डेटा पास नहीं कर सकता। रेंडर करने के बाद यह केवल स्पष्ट html दिखाता है, बिना Vue के डेटा के। सभी काम करता है, लेकिन डेटा के बिना ((
App.js से मेरा कोड:
var Series = Vue.component('Series', require('./components/Series.vue'),{
props: {
series: {
type: Array,
default: []
},
images: {
type: Array,
default: []
},
showPhotos: {
type: Boolean,
default: false
}
}
});
const Bar = { template: '<div>bar</div>' }
const Foo = { template: '<div>foo</div>' }
const routes = [
{ path: '/weedings', component: Series },
{ path: '/', component: Foo },
{ path: '/family', component: Foo },
{ path: '/other', component: Foo },
{ path: '/videos', component: Bar },
{ path: '/blog', component: Bar },
{ path: '/about', component: Foo },
{ path: '/contacts', component: Bar }
]
const router = new VueRouter({
routes // short for routes: routes
});
var app = new Vue({
el: "#app",
router,
data: {
series: [],
currentSerie: 0,
images: [],
showPhotos: false
},
methods: {
fetchSeries: function(){
this.$http.get('/api/fetchSeries').then((response) => {
this.series = response.body
}, (response) => {
alert("fail")
});
},
fetchPhotos: function(id){
this.showPhotos = false;
this.$http.get('/api/fetchPhotos/'+id).then((response) => {
this.images = response.body
this.showPhotos = true;
$("html, body").animate({ scrollTop: 60 }, "500");
}, (response) => {
alert("fail")
});
},
photos: function(id){
this.fetchPhotos(id)
}
},
created: function(){
this.fetchSeries()
setTimeout(function(){ require('./custom'); }, 1000);
}
});
जब मैं वू-राउटर का उपयोग नहीं करता, तो सब ठीक काम करता है। और मुझे पता है कि मैं इस तरह से घटकों को डेटा पास कर सकता हूं: <my-component :artribute="value"></my-component>
, लेकिन इस मामले में आईडीके डेटा कैसे पास करें।
2 जवाब
इस तरह फ़ंक्शन मोड का प्रयोग करें:
{
path: '/weedings',
component: Series,
props: () => (
{ series: app.series, images: app.images, showPhotos: app.showPhotos }
)
}
JSFiddle में काम करने का उदाहरण देखें।
नोट: आपको vuex के सभी घटकों के लिए एक केंद्रीकृत स्टोर के रूप में उपयोग करना होगा अधिक जटिल परिदृश्यों को लागू करने में सक्षम होने के लिए एक आवेदन।
अपने मार्गों की घोषणा में आपको सहारा जोड़ना चाहिए
`const routes = [
{ path: '/weedings', component: Series, props: true}]`
यहाँ उल्लेख किया गया है: Vue.js घटकों के लिए प्रॉप्स पास करना Vue-router द्वारा तत्काल किया गया
संबंधित सवाल
जुड़े हुए प्रश्न
नए सवाल
laravel
लारवेल एक स्वतंत्र, ओपन-सोर्स PHP वेब फ्रेमवर्क है, जो टेलर ओटवेल द्वारा निर्मित और मॉडल-व्यू-कंट्रोलर (एमवीसी) आर्किटेक्चरल पैटर्न और सिम्फनी पर आधारित वेब अनुप्रयोगों के विकास के लिए अभिप्रेत है। लारवेल का स्रोत कोड GitHub पर होस्ट किया गया है और MIT लाइसेंस की शर्तों के तहत लाइसेंस प्राप्त किया गया है।
Vue.component()
में दूसरा पैरामीटर क्या है, मैंने घटक पंजीकरण के लिए तीन पैरामीटर वाले हस्ताक्षर कभी नहीं देखे, लेकिन मैं गलत हो सकता हूं।Vue.component()
कॉल के दो पैरामीटर हैं जो सही है, यहां आपके कोड में तीन हैं।Vue.component
कई बार कॉल नहीं करना चाहिए (Series
शीर्ष पर एक बार पंजीकृत है, फिर मार्ग परिभाषा में फिर से पंजीकृत है)।var Series = Vue.component('Series', require('./components/Series.vue'),{ props: { series: { type: Array, default: [] }, images: { type: Array, default: [] }, showPhotos: { type: Boolean, default: false } } }); const routes = [ { path: '/weedings', component: Series }, ]