question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Can i use mixins global in vue? i am use typescript with vue

See original GitHub issue
mounted() {
    Vue.$notify("OK", "success", "notify", 2000);
  }

if i call function $notify (in file mixins and declared in main.ts) by this or Vue. ts will show error this function doesn’t exist in module. So how to can call this function in the component?

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

10reactions
bestickleycommented, Jul 26, 2019

Solution:

//inside src/mixins.ts
import { Component, Vue } from "vue-property-decorator";

@Component
export default class Mixin extends Vue {
  toCurrency(number: number) {
      const formatter = new Intl.NumberFormat("en-US", {
        style: "currency",
        currency: "USD",
        minimumFractionDigits: 2
      });
      return formatter.format(number);
    }
}
//inside src/main.ts
import mixins from "@/mixins";
Vue.mixin(mixins)
// inside src/types.d.ts
import Vue from "vue";
declare module "vue/types/vue" {
  interface Vue {
    toCurrency(number: number): string;
  }
}
// inside src/App.vue\
const amount = this.toCurrency(1000);
1reaction
bestickleycommented, Jul 28, 2019

Yep, I’m sure it works for me. I’m not sure why it wouldn’t be working for you 😦

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to access global mixin's methods in TypeScript Vue ...
Based on the example from vue-class-component docs, the mixin takes the same form as a component: src/mixin.ts: import Vue from 'vue' import ...
Read more >
Vue Global Mixin with TypeScript - Get Help
I seem to be having an issue with the typing using global mixins. The code itself actually works, and my IDE seems to...
Read more >
How to type check your vue nuxt global mixins. - YouTube
In this video, I show you how to use typescript and Vue to type-check your mixins in Nuxt js Follow me on ...
Read more >
How to use mixin in VueJS typescript? | by Angel iT - Medium
In vue decoration document, I saw that we can pass multiple mixins into mixins helper function, so now we can use AbpBase as...
Read more >
Vue V3 with mixin and typescript : r/vuejs - Reddit
I am converting my app to use typescipt. So I have a global mixin (bunch of helper methods) that all my Vue components...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found