如何在vuejs中导出javascript的数据?

How to export data from javascript in vuejs?

我有一个 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');
            });
        });
    }
}

ymaps.ready(function () {

创建一个新范围,因此 this 不再是您的 Vue 应用程序。

替换为

ymaps.ready(() => {

或在该函数末尾添加 .bind(this)