问题记录贴:vue-i18n在弹出框中$t()报错:TypeError: Cannot read property '_t' of undefined

发布时间 2023-10-11 15:38:08作者: 沐木琴

网上有用的解决方法:vue 国际化在弹出框中$t()报错:TypeError: Cannot read property '_t' of undefined

大佬给出的解决方法:
弹窗是一个新的Vue对象,只需要单独给弹窗重新绑定i18n即可。
代码:

// dialog/main.js
import customDialog from './dialog.vue'
import i18n from '@/i18n'

const NewDialog = Vue.extend(customDialog)

function 弹窗工厂(config) {
	// 具体代码参考elementui弹窗源码
	...
	...
	const Dialog = function (options) {
	...
		const instance = new NewDialog ({
			i18n,
			data
		})
		instance.$mount()
		....
	}
	....
	return Dialog
}

export default 弹窗工厂