vuejs フォームと純粋な JS ベースのマップ ウィジェットがあります。マップ (vanilla js) からフォーム入力 (vuejs) に座標を抽出する必要があります。どうやってやるの?意見:
<el-form :model="storeForm" label-width="200px" ref="storeForm" status-icon size="small">
<el-form-item label="Address" prop="Address">
<el-input v-model="storeForm.Address" type="textarea"></el-input>
</el-form-item>
<el-form-item>
<div id="map" style="width: 600px; height: 400px"></div>
</el-form-item>
<el-form-item>
<el-button type="primary" @click="save('storeForm')">Save</el-button>
<el-button @click="cancel()">Cancel</el-button>
</el-form-item>
</el-form>
そして vuejs コード:
export default {
data() {
return {
isNew: true,
storeForm: {
Address: ''
}
}
},
created() {
ymaps.ready(function () {
var map = new ymaps.Map("map", {
center: [43.241203, 76.957206],
zoom: 13
});
map.events.add('click', (e) => {
var coords = e.get('coords');
//obviously that doesn't work
this.storeForm.Address = e.get('coords');
});
});
}
}