const obj = Object.assign({}, ...arr.map((n, i) => ({ [n]: arr2[i] })));
// или
const obj = arr.reduce((acc, n, i) => ({ ...acc, [n]: arr2[i] }), {});
const combine = (keys, values) =>
keys.reduce((acc, n, i) => (acc[n] = values[i], acc), {});
const obj = combine(arr, arr2);
// store.js
export default {
a: 'foo',
b: 'bar'
}
import Vue from 'vue'
import Store from './store'
new Vue({
el: '#app',
data: Store,
render: h => h(App)
})
<template>
<div>{{$root.a}}</div>
</template>
<script>
import Store from './store'
export default {
name: 'app',
methods: {
test () {
this.$root.a = 'something value'
}
}
}
<form>
<div class="form-group">
<label for="InputFile">File input</label>
<input type="file" id="InputFile" @change="onFileChange">
<p class="help-block">Upload image</p>
</div>
</form>
onFileChange (e) {
let file = e.target.files[0] || e.dataTransfer.files[0]
let formData = new FormData()
formData.append('image', file)
this.$http.post('upload/', formData)
.then(response => {
console.log(response)
}, error => {
console.log(error)
})
}