1.使用renderjs引用ol.js
// 使用renderjs.
<script module="renderMap" lang="renderjs">
import "@/static/css/ol.css";
</script >
//引入ol.js
mounted() {
if (typeof window.ol === 'function') {
this.initMap()
} else {
// 动态引入较大类库避免影响页面展示
const script = document.createElement('script')
script.src = 'https://cdn.bootcdn.net/ajax/libs/openlayers/4.6.5/ol.js'
script.onload = this.initMap.bind(this)
document.head.appendChild(script)
}
},
2.renderjs会导致uniapp很多原生写法不支持
1.接口请求
getPointData() {
let self = this;
var xhr = new XMLHttpRequest();
xhr.onreadystatechange = function() {
if (xhr.readyState === 4) {
self.addPoint(JSON.parse(xhr.response))
}
}
xhr.open('get', this.url + 'manage/stroe/allList', false)
xhr.send();
},
2.click事件
直接@click方法在手机端找不到方法,需要加上module名
//@click要加上<script module="renderMap" lang="renderjs"> 里面的module名,
<view class="searchs">
<input id="test_input" type="text" placeholder="名称" placeholder-class="placeholder" v-model="name"
confirm-type="search" />
<image src="../../static/icon001_1.png" class="icons posY_center"></image>
<view class="buttonsw" @click="renderMap.searchPoint">搜索</view>
</view>
3.数据绑定问题
input 值 v-model=“name” ,浏览器测试可以获取到,手机上就不行。
获取方法如下
var name =document.getElementById("test_input").getElementsByTagName("input")[0].value;