Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

mstfkhazaal's avatar

I cannot access to mixin funtions

Version:

Describe the problem:

app.js

import { createApp, h } from 'vue'
import { createInertiaApp } from '@inertiajs/vue3'
import {base} from '@/base'

createInertiaApp({
  resolve: name => {
    const pages = import.meta.glob('./Pages/**/*.vue', { eager: true })
    return pages[`./Pages/${name}.vue`]
  },
  setup({ el, App, props, plugin }) {
    createApp({ render: () => h(App, props) })
      .use(plugin)
      .mixin(base)
      .mount(el)
  },
})

base.js

export const base = {
    methods: {
        /**
         * Translate the given key.
         */
        tr(key, replace = {}) {
            let translation = this.$page.props.language[key]
                ? this.$page.props.language[key]
                : key;

            Object.keys(replace).forEach(function (key) {
                translation = translation.replace(':' + key, replace[key])
            });

            return translation
        },
   
    
    }
};

Login.vue

<script lang="ts" setup>
console.log(this.tr('welcome')); /// Error
</script>
<template>
<p>{{tr('welcome')}}</p> // Work
</template>

I cannot access to method tr from setup

0 likes
2 replies
vjupix's avatar

Same problem over here. Seems like inertia does not allow mixins anymore? Nothing on the net works for me in recent version. Always getting something like Uncaught (in promise) TypeError: _ctx.myfunction(...) is not a function

Abhishek0116's avatar

You need to add methods inside mixin like this

.mixin({
  methods: {
    base,
  }
})

Your full code with modification

import { createApp, h } from 'vue'
import { createInertiaApp } from '@inertiajs/vue3'
import {base} from '@/base'

createInertiaApp({
  resolve: name => {
    const pages = import.meta.glob('./Pages/**/*.vue', { eager: true })
    return pages[`./Pages/${name}.vue`]
  },
  setup({ el, App, props, plugin }) {
    createApp({ render: () => h(App, props) })
      .use(plugin)
      .mixin({
        methods: {
          base,
        }
      })
      .mount(el)
  },
})

Please or to participate in this conversation.