I am a novice, expecting VUER to give me the strength to move forward. I encountered a problem. I couldn"t find out many solutions for two days.
this is the sub-component code I wrote:
Vue.component("list-ol",{
props:["name_en","name_cn"],
created:function(){
},
template:`
<li class="li-catalog pull-left">{{ name_cn }} {{ name_en }}
<span v-on:click="$emit("pronouce", name_en)" class="glyphicon glyphicon glyphicon-headphones headphone-icon"></span></li>
`
});
var app = new Vue({
el:"-sharpapp",
data:{
catalogList:[],
level:""
},
created: function(){
this.getCatalogList();
this.levelHandler();
},
methods:{
// word$emit
// vm.$emit( eventName, [args] )
// :
// {string} eventName
// [...args]
//
pronouce:function(word){
pronouceIt(word);
},
levelHandler:function(level){
//Vue.set(this,"level",lvl);
//alert(level);
},
getCatalogList:function(event){
var componentObj = this;//In case of "this" will be pointed to Jquery object
//:JQUERYAJAXJSONVUE
$.getJSON("getcataloglist.php", {act: "fetchcatalog",level:"1"}, function(json, textStatus) {
Vue.set(componentObj,"catalogList",json);
});
}
}
});
this is HTML"s COMPONENT:
<level-tip **level="1"**></level-tip>
<ol>
<list-ol v-on:pronouce="pronouce"
v-on:levelHandler ="levelHandler"
v-for="item in catalogList"
v-bind:key="item.Id"
v-bind:name_en="item.name_en"
v-bind:name_cn="item.name_cn"
>
</list-ol>
The level=1 in means that if I want to reuse this COMPONENT, I just need to change the level=2, in it and pass this value to $.getJSON to get different data blocks, so that I can display different contents in the list-ol. (this level=1 should be better placed in the list-ol component? )
asked a lot of questions at once. I don"t know if my question is clear. Thank you