How to use vue-moment in vuex - vue.js

Im using this vue-moment library without any problem. But I can't use it in Vuex.
I tried:
this.$moment()
this.moment()
---
import vue from 'vue'
vue.moment()
---
import vueMoment from 'vue-moment'
vueMoment.moment()
and always get an error.

When using vue-moment in a vuex module you can't use this.$moment but you can use it like this:
import Vue from 'vue'
...
Vue.moment(someTime)

First, use it as a plugin Vue.use(require('vue-moment')); before starting the instance of the vue instance
secondly you can use it like this as an exampleVue.moment().. just replicated and it worked
this is how the start of my file looks like
import Vue from 'vue';
import Vuex from 'vuex';
Vue.use(Vuex);
Vue.use(require('vue-moment'));
export default new Vuex.Store({
//the rest of the state.js file
})

Related

Bootstrap-vue bvModal Header Close Issue

I'm new to use Bootstrap-vue, since I use CDN reference to use it, it work abd perfect for me. Now I try to change webpack version, I face on some issue.
This is CDN version of bvModal.msgBoxOk method
this is webpack version of bvModal.msgBoxOk method
you can see the different in top of "X" button, I don't know which step I missing. The following is my main.ts file
// Import Bootstrap an BootstrapVue CSS files (order is important)
import 'bootstrap/dist/css/bootstrap.css'
import 'bootstrap-vue/dist/bootstrap-vue.css'
import Vue from 'vue';
import { BootstrapVue, IconsPlugin } from 'bootstrap-vue'
// Make BootstrapVue available throughout your project
Vue.use(BootstrapVue);
// Optionally install the BootstrapVue icon components plugin
Vue.use(IconsPlugin);
Any body can help me?

Error on importing VueAnalytics to main.ts in Vue CLI (Vue3)

The following error message is given:
"Argument of type 'typeof VueAnalytics' is not assignable to parameter of type 'Plugin_2'.
Type 'typeof VueAnalytics' is not assignable to type '{ install: PluginInstallFunction; }'.
Types of property 'install' are incompatible."
What am I doing wrong ? Thank you very much for your help.
import { createApp } from "vue";
import App from "./App.vue";
import "./registerServiceWorker";
import router from "./router";
import store from "./store";
import VueAnalytics from "vue-analytics";
createApp(App)
.use(store)
.use(VueAnalytics, {id:'', router})
.mount("#app");
This error indicates that the plugin was built for Vue 2 and is not compatible with Vue 3. Checking the package's npm page reveals that there have been no updates in the last year. The requirement also lists Vue 2.
The last Github commit was in January.
Following some links from the package's Github leads to this package which looks like it may work with Vue 3.

How to use imports globally in Vue-Application?

I am teaching myself some Vue.js and after finding out about view-router I have to restructure my project.
How can I use my import (bulma, fontawesome, bulma-calendar...) in every view/component and import it only once?
I'd appreciate a hint. Thanks
In case if you want to use styles file globally you can import it inside your App.vue in style section.
<style lang="scss">
//your imports here
</style
If you want to import js files globally you can do it in your main.js file
In vue2 vue plugins are connected in this way:
import Vue from "vue";
import PluginName from "pulin-name";
Vue.use(PluginName);
For vue3 use:
import { createApp } from "vue";
import PluginName from "plugin-name";
const app = createApp(...);
app.use(PluginName);
Correct way should be described in plugin documentation, so read it before start to use in your project.

Vue CLI 4.5.*: "export 'default' (imported as 'Vue') was not found in 'vue'

While working with Vue CLI 4.5.x, I tried the following code:
import Vue from "vue"
import App from './App.vue'
new Vue({
el: "#app",
render: h=> h(App)
})
But unfortunately, it gave the following warnings:
"export 'default' (imported as 'Vue') was not found in 'vue'
What I can conclude from this, is that Vue CLI 4.5.x has stopped this way of creating an application where you first create a Vue instance.
To initialize the main application, the official way is as follows:
import { createApp } from 'vue'
import App from './App.vue'
createApp(App).mount('#app')
I'm not sure if my conclusion is correct or not. It would be a great help if somebody would concrete my conclusion, as so far I have not found any proof of that in official documentation of vue.
Moreover, the later code comes baked with Vue CLI 4.5.* application instance, while former code is true when using the CDN.
You've installed vue 3 using vue-cli 4 and this version has this new global api for creating new app :
import { createApp } from 'vue'
const app = createApp({})
You're still able to create apps using vue 2 based on vue cli 4 but you should indicate the version when you launch new project.

Import a plugin in Vue from local file

i want add a vue panel in my project : vue-black-dashboard
in documentation :
Vue Black Dashboard is built as Vue plugin so you can simply import it
and use it.
import Vue from 'vue';
import DashboardPlugin from '#/plugins/blackDashboard'
Vue.use(DashboardPlugin);
but i dont know where paste vue-black-dashboard folder
how i can import it to my project
thanks
If you want to import it and use in a local component, just import it in component.
<script>
import Vue from 'vue';
import DashboardPlugin from '#/plugins/blackDashboard'
Vue.use(DashboardPlugin);
export default {
}
</script>
If you want to import it and use globally, just import it in main.js.
import Vue from 'vue';
import DashboardPlugin from '#/plugins/blackDashboard'
Vue.use(DashboardPlugin);
hello thanks for your answer
import DashboardPlugin from '#/plugins/blackDashboard'
where is the # in this address ?
i want use this template in specify route of my project
when i import it in main.js
This dependency was not found:
#/plugins/blackDashboard in ./src/main.js
To install it, you can run: npm install --save
#/plugins/blackDashboard
How's your plugin file look like? I have a similar issue with having plugins in separate files in /plugins directory and importing them to main.js
What I'm trying to achieve is better structure of plugins to keep them in separate files in folder plugins, rather than storing all the code in main.js
Not sure is it allowed or is it a good practice.
Plugins folder: plugins/toastification.js
import Vue from 'vue'
import Toast from 'vue-toastification'
import 'vue-toastification/dist/index.css'
const options = {
position: 'bottom-right'
}
Vue.use(Toast, options)
// export default new Toast() - got error while exporting but it works somehow without export default I don't know why
Part of main.js
// plugins
import vuetify from './plugins/vuetify'
import i18n from './plugins/i18n'
import toastification from './plugins/toastification'
import logger from './plugins/logger'
new Vue({
vuetify,
i18n,
toastification,
logger,
render: h => h(App)
}).$mount('#app')