Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I'm struggling with this error. this error is occured at

error  Parsing error: Unexpected token

   7 | 
   8 | Vue.config.productionTip = false
>  9 | declare global{
     |         ^
  10 |   interface Window{
  11 |     getAlert : any;
  12 |   }

I found many answers exist and I followed but it's not working. Many answers are likely adding this senetence.

    parser: 'babel-eslint'

but this option is already done when the project is created.

.eslintrc.js

module.exports = {
  root: true,
  env: {
    node: true
  },
  'extends': [
    'plugin:vue/essential',
    'eslint:recommended'
  ],
  parserOptions: {
    parser: 'babel-eslint'
  },
  rules: {
    'no-console': process.env.NODE_ENV === 'production' ? 'warn' : 'off',
    'no-debugger': process.env.NODE_ENV === 'production' ? 'warn' : 'off'
  }
}

main.ts

import Vue from 'vue'
import App from './App.vue'
import './registerServiceWorker'
import router from './router'
import store from './store'
import vuetify from './plugins/vuetify'

Vue.config.productionTip = false
declare global{ 
  interface Window{
    getAlert : any;
  }
}

var vm = new Vue({
  router,
  store,
  vuetify,
  methods:{
    getAlert(){
         alert(11111)
       }
  },
  render: h => h(App)
}).$mount('#app')

window.getAlert = vm.getAlert

How to solve this problem? I really want to make a window property.

common.d.ts(updated)

declare global{ 
  interface Window{
    getAlert : any;
  }
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
1.0k views
Welcome To Ask or Share your Answers For Others

1 Answer

等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...