最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Vue.js Syntax Error (SCRIPT1003) IE11 and lower - Stack Overflow

programmeradmin1浏览0评论

When i try my vue.js app in IE11 or lower i get Error SCRIPT1003 excepted : in the console which points to routeContent. My Snytax looks like this:

var store = new Vuex.Store({
    state: {
        routeContent: null
    },
    mutations: {
        routeContent(state, payload) {
            state.routeContent = payload
            document.title = payload.title
        }
    }
})

When i try my vue.js app in IE11 or lower i get Error SCRIPT1003 excepted : in the console which points to routeContent. My Snytax looks like this:

var store = new Vuex.Store({
    state: {
        routeContent: null
    },
    mutations: {
        routeContent(state, payload) {
            state.routeContent = payload
            document.title = payload.title
        }
    }
})
Share Improve this question asked Oct 27, 2016 at 9:42 janthomajanthoma 932 silver badges7 bronze badges 1
  • Are you using a transpiler (e.g. Babel)? – Joe Clay Commented Oct 27, 2016 at 9:48
Add a ment  | 

2 Answers 2

Reset to default 3

You're trying to use the object method shorthand in your definition of routeContent - this isn't supported in Internet Explorer or Safari.

The two options you have are to either start using a transpiler such as Babel to convert modern JS syntax into a form that older browsers can understand - or, if that's too much hassle, you could just switch back to using the good old-fashioned function syntax:

var store = new Vuex.Store({
    state: {
        routeContent: null
    },
    mutations: {
        routeContent: function (state, payload) {
            state.routeContent = payload
            document.title = payload.title
        }
    }
})

Here is another similar question: javascript Ajax SCRIPT1003: Expected ':' in IE 11

I think you may have to do as follows:

mutations: {
    routeContent: function(state, payload) {  // making it obvious that this is a function
        state.routeContent = payload;
        document.title = payload.title;  // and also the semicolons
    }
}
发布评论

评论列表(0)

  1. 暂无评论