在vue中created、mounted等方法使用小結
created:html加載完成之前,執行。執行順序:父組件-子組件
mounted:html加載完成后執行。執行順序:子組件-父組件
methods:事件方法執行
watch:watch是去監聽一個值的變化,然后執行相對應的函數。
computed:computed是計算屬性,也就是依賴其它的屬性計算所得出最后的值
export default { name: 'draw', data(){ // 定義變量sourcereturn { source:new ol.source.Vector({wrapX: false}), } }, props:{ //接收父組件傳遞過來的參數 map:{ //type:String }, },mounted(){ //頁面初始化方法 if (map==map){ } var vector = new ol.layer.Vector({ source: this.source }); this.map.addLayer(vector); }, watch: { //監聽值變化:map值 map:function () { console.log(’3333’+this.map); //return this.map console.log(’444444’+this.map); var vector = new ol.layer.Vector({ source: this.source }); this.map.addLayer(vector); } }, methods:{ //監聽方法 click事件等,執行drawFeatures方法 drawFeatures:function(drawType){}}
補充知識:vue中在mounted中window.onresize不生效
在vue開發中,因為引用的父組件和子組件都使用了window.onresize以至于一個window.onresize失效。
解決方案==>可以采用下面的方式
window.onresize = () => this.screenWidth = window.innerWidth // 改為以下寫法window.addEventListener(’resize’, () => this.screenWidth = window.innerWidth, false)
以上這篇在vue中created、mounted等方法使用小結就是小編分享給大家的全部內容了,希望能給大家一個參考,也希望大家多多支持好吧啦網。
相關文章:
1. ThinkPHP5 通過ajax插入圖片并實時顯示(完整代碼)2. javascript設計模式 ? 建造者模式原理與應用實例分析3. Python使用oslo.vmware管理ESXI虛擬機的示例參考4. Java構建JDBC應用程序的實例操作5. IntelliJ IDEA設置條件斷點的方法步驟6. Express 框架中使用 EJS 模板引擎并結合 silly-datetime 庫進行日期格式化的實現方法7. 一篇文章帶你了解JavaScript-對象8. python flask框架快速入門9. 解決Python paramiko 模塊遠程執行ssh 命令 nohup 不生效的問題10. Ajax引擎 ajax請求步驟詳細代碼
