本文以 `React`、`Vue` 為例,介紹下主流的渲染模式以及在主流框架中如何實現上述的渲染模式。 ## 前置知識介紹 看渲染模式之前我們先看下幾個主流框架所提供的相關能力,瞭解的可跳到下個章節。 ### 掛載組件到 DOM 節點 這是主流框架最基本的能力,就是將組件渲染到指定的 `DOM` 節 ...
前端Vue基於騰訊地圖Api實現的選擇位置組件 返回地址名稱詳細地址經緯度信息, 下載完整代碼請訪問uni-app插件市場地址:https://ext.dcloud.net.cn/plugin?id=13310
效果圖如下:
使用方法
<!-- leftTitle:左邊標題 name:輸入框名字 value:輸入框選擇值 placeholder:占位符 @click:點擊事件-->
<cc-locPicker leftTitle="收穫地點" name="location" :value="mapSelData.poiname" placeholder="請選擇位置"
@click="chooseAddress"></cc-locPicker>
<!-- 跳轉騰訊雲地圖Api 頁面實現 -->
<template>
<view class="map">
<!-- 騰訊地圖Api key:騰訊地圖key -->
<web-view
src="https://apis.map.qq.com/tools/locpicker?search=1&type=1&key=SFABZ-WANWW-FISRY-3IGTF-HV7RE-YSFTI&referer=myapp"></web-view>
</view>
</template>
<script>
// 引入設置地址存儲工具
import {
setlocation
} from './utils.js'
// #ifdef H5
window.addEventListener('message', event => {
// 接收位置信息,用戶選擇確認位置點後選點組件會觸發該事件,回傳用戶的位置信息
var loc = event.data;
if (loc && loc.module == 'locationPicker') {
//防止其他應用也會向該頁面post信息,需判斷module是否為'locationPicker'
let location = {
poiaddress: loc.poiaddress,
poiname: loc.poiname,
latlng: loc.latlng
}
// 設置存儲地址信息
setlocation(location)
uni.navigateBack();
}
}, false);
// #endif
</script>
<style></style>
HTML代碼實現部分
<template>
<view class="content">
<form @submit="formSubmit" @reset="formReset">
<!-- leftTitle:左邊標題 name:輸入框名字 value:輸入框選擇值 placeholder:占位符 @click:點擊事件-->
<cc-locPicker leftTitle="收穫地點" name="location" :value="mapSelData.poiname" placeholder="請選擇位置"
@click="chooseAddress"></cc-locPicker>
<ccInputView leftTitle="詳細地址" name="address" :value="mapSelData.poiaddress" placeholder="請輸入詳細地址">
</ccInputView>
<ccInputView leftTitle="經度信息" name="lng" :value="mapSelData.latlng.lng" placeholder="請輸入精度信息">
</ccInputView>
<ccInputView leftTitle="緯度信息" name="lat" :value="mapSelData.latlng.lat" placeholder="請輸入緯度信息">
</ccInputView>
<view class="uni-btn-v">
<button class="botBtn" type="primary" form-type="submit">下一步</button>
<view class="tipText"> 註意事項: 請確保您填寫的收穫位置準確 </view>
</view>
</form>
</view>
</template>
<script>
import ccInputView from '../../components/ccInputView.vue'
// 獲取地址工具
import {
getlocation
} from './utils.js'
export default {
components: {
ccInputView
},
data() {
return {
mapSelData: {
"latlng": {}
},
}
},
/**
* 生命周期函數--監聽頁面顯示
*/
onShow: function() {
// #ifdef H5
let locations = getlocation() //獲取位置信息
if (locations) {
this.mapSelData = locations
uni.clearStorageSync();
}
// #endif
},
methods: {
formSubmit: function(e) {
console.log('form發生了submit事件,攜帶數據為:' + JSON.stringify(e));
var formdata = e.detail.value;
uni.showModal({
title: '溫馨提示',
content: 'formsubmit事件攜帶數據為:' + JSON.stringify(e.detail.value)
})
},
// 選擇地址
chooseAddress(e) {
let myThis = this;
uni.navigateTo({
url: './h5map'
})
},
}
}
</script>
<style>
.content {
display: flex;
flex-direction: column;
}
.uni-btn-v {
width: 100%;
height: auto;
}
.botBtn {
width: 90%;
margin-top: 36px;
}
.tipText {
width: 100%;
margin-left: 0px;
text-align: center;
color: #666666;
margin-top: 36px;
margin-bottom: 36px;
font-size: 28rpx;
}
</style>