The child component cannot listen for clicks
Need @ the click. Native = "XXXX"Copy the code
### Refresh frequently
– stabilization (debounce)
debounce(func,delay){let timer = nullreturn function(... args)={if(timer){clearTimeout(timer)}setTimout(()=>{func.apply(this,args)},delay)}}const refresh = debounce(this.$refs.scroll.refresh)this.$bus.$on("itemImgLoad", () => {refresh()Copy the code
Avoid more than two layers {{xx.xx.xxxx}}
To use,
, you can resolve the error
The DOM is not rendered without data
<div v-if=" object.keys (< Object >.length! < object > render the element and its children if the length is not zeroCopy the code
### Get the element of the $refs. XXX component
This.$refs.xxx.$el.offsetTop// Get the top position of the XXX elementCopy the code
` ` `
Better Scroll problem
ScrollTo moves to the specified position
scrollTo(x,y)
Problem getting scroll position
Encapsulating probeType defaults to 0, which is also 0 for native and does not listen.
Need to pass in from component :probe-type=”3″
for in
` ` `
for(i in xxx){
Log. I //’ I ‘is a string
}
` ` `
### The choice of using (central event bus) $BUS or VUEX
` ` `
If both components are determined to be loaded, both can be used
Do not use $bus if a component may not be loaded in the interim and cannot send bus events
` ` `
### $bus
` ` `
Event. $emit (‘ MSG ‘, this MSG); To send data, the first parameter is the name of the data to be sent and received with that name, and the second parameter is the current location of the data;
Event. $on (‘ MSG ‘, function (MSG) {receiving data, the first parameter is the name of the data, and send the name of the corresponding, the second parameter is a way, to the operation of the data
/ Here are operations on data
})
` ` `
The view cannot be updated when using VUEX cache data
` ` `
data(){
return {
/ / url: this. $store. State. The detail. PlayUrl, / / if it going to be updated
A :’1′, // The data in this component can update the view by changing the value three seconds after the Created life cycle
}
},
computed:{
// You need to put store dynamic data in computed to update the view synchronously
getPlayUrl(){
return this.$store.state.detail.playUrl
}
},
` ` `
### Vuex getters maps to components
` ` `
import {mapGetters} from ‘vuex’
computd:{
. MapGetters ([‘ method to use in getters ‘]),
}
computd:{
. mapGetters({
Aliases: ‘Method name to use in getters’
},),
}
` ` `
Vuex Actions map to components
` ` `
import {mapActions} from ‘vuex’
methods:{
. MapActions ([‘ function name ‘]),
}
` ` `
# # adaptation
Static import
require(‘assets/icon/home.svg’)