onUploadProgress({loaded, total}) {
const uploadProgress = Math.round(loaded / total * 100)
store.commit('uploader/setProgress', uploadProgress)
}
export const uploader = {
namespaced: true,
state: {
progress: 0
},
mutations: {
setProgress(state, progress) {
state.progress = progress
}
}
}
computed: {
...mapState('uploader', [
'progress'
])
}
<template>
<div>{{progress}}%</div>
</template>
const jwt = {
payload: {
idle: 900000 // 15min * 60s * 1000ms
}
}
setInterval(() => {
user.logout()
}, jwt.payload.idle)
<InputText
:value="userName"
@input="handleUserName($event)">
</InputText>
computed: {
userName: {
get() {
return this.$store.state.administration.user.name
},
set(value) {
this.$store.commit('setUserName', value)
}
}
},
methods: {
handleUserName(value){
this.userName = value
}
}
methods: {
openPopup() {
this.$store.dispatch('loadUser')
.then(() => {
this.popupOpen = true
})
}
}
// i18n.js
import Vue from 'vue'
import VueI18n from 'vue-i18n'
import english from '@/lang/english.js'
import russian from '@/lang/russian.js'
Vue.use(VueI18n)
let messages = {
en : english,
ru : russian,
}
export default new VueI18n({
//locale: 'ru',
locale: window.localStorage.Language || 'ru',
fallbackLocale: 'ru',
messages
})
// router.js
...
import i18n from '@/path/to/i18n.js'
...
{
path: '/about',
component: About,
meta: { title: i18n.t('about') }
}
// main.js
import Vue from 'vue'
import App from './App'
import Vuetify from 'vuetify'
import router from './router'
import axios from 'axios'
import store from './store';
import i18n from '@/path/to/i18n.js'
Vue.config.productionTip = false
Vue.use(Vuetify)
Vue.axios = Vue.prototype.$http = axios.create({
baseURL: 'http://localhost:5000/api'
})
/* eslint-disable no-new */
new Vue({
el: '#app',
i18n,
router,
store,
components: { App },
template: '<App/>',
created() {
this.$vuetify.theme.primary = '#01579B'
}
})
const comp = Vue.component('comp', {
...
data() {
return state
},
...
})
const state = Vue.observable({ z: false });
const comp = Vue.component('comp', {
...
mapCreated: function ($map) {
const _this = this;
// далее идет код
}
let currentCoords
на _this.currentCoords
mapCreated: function ($map) {
const _this = this
let pointOnMap = new ymaps.Placemark([55.7204,37.6200], {}, {
draggable: true
});
$map.geoObjects.add(pointOnMap);
this.map = $map;
let coords = [55.7204,37.6200]
pointOnMap.events.add("dragend", function (e) {
let coords = this.geometry.getCoordinates();
_this.currentCoords = coords[1].toFixed(6) + ',' + coords[0].toFixed(6);
}, pointOnMap);
}
<Box v-for="(item, index) in subset"
...
:ref="`ref${index}`">
Vue.nextTick( () => {
this.$refs.ref2[0].$el.clientWidth;
...
});
https://mysite.com/news/:id
methods: {
getNewsComments() {
const newsId = this.$route.params.id
axios.get(`/news/${newsId}/comments`).then(...)
}
}
actions: {
fetchData({commit}) {
return axios.get('apiurl').then(response => {
commit('setData', response.data)
})
}
}
computed: {
...mapState(['data'])
},
methods: {
...mapActions(['fetchData'])
},
async created () {
if (!this.data) {
await this.fetchData();
console.log(this.data)
}
}