Parent component have method
layoutMain.vue
<script lang="ts">
....
hideRightSidebar() {
document.body.classList.remove('right-bar-enabled')
}
....
</script>
<template>
<div id="wrapper">
....
</div>
<Rightbar />
</div>
</template>
in child component "Rightbar" i want call parent method
if not use typescript i just call
<script>
export default {
name: "RightBar"
....
methods: {
handleRightBarClick(e, el) {
this.$parent.hideRightSidebar()
},
and all work, but if I add TS lang
<script lang="ts">
import { Vue } from 'vue-property-decorator'
export default class RightBar extends Vue {
handleRightBarClick(e: any, el: any) {
(this.$parent as any).hideRightSidebar()
}
....
i have error
TypeError: Cannot read property '$parent' of undefined
how fix that?
I also have a question about accessing the i18n plugin
in nuxt.config.js i have a setting:
nuxt.config.js
....
i18n: {
locales: ["en", "fr", "es", "ar"],
defaultLocale: "en",
vueI18n: {
fallbackLocale: "en",
messages: {
en: require("./locales/en.json"),
fr: require("./locales/fr.json")
}
}
}
....
it works fine, if I don't use TS
<script>
export default {
data() {
return {
....
current_language: this.$i18n.locale
};
},
....
but if I use TS, I have error
current_language: this.$i18n(<-- error HERE).locale
Property '$i18n' does not exist on type 'Readonly<Record<never, any>> & Vue'
how fix that?