When defining an object using JSON format in JavaScript
An error occurred while debugging the browser: uncaught syntax error: invalid shorthand property initializer
<body>
<div id=app>
<button @click="handclick">Button</button>
<p>{{name}}</p>
</div>
</body>
<script src="./js/vue.js"></script>
<script>
let app = new Vue({
el: "#app",
// The reason is that "=" should be written as ":"
data: {
name: "张三"
},
methods: {
handclick() {
this.name = 'lis'
}
},
watch: {
name(newVal, oldVal) {
console.log(newVal, oldVal)
}
}
})
</script>
Read More:
- About JS error uncaught syntax error: invalid shorthand property initializer
- [Solved] Uncaught SyntaxError: Invalid Unicode escape sequence
- [Solved] Uncaught SyntaxError: Cannot use import statement outside a module
- [Solved] Vue Error: Uncaught TypeError: Vue.createApp is not a function
- [Solved] ajax Error: Uncaught SyntaxError: Unexpected end of JSON input
- Method to solve uncaught typeerror: cannot set property ‘onclick’ of null error
- [Solved] JS Error: Uncaught SyntaxError: Illegal return statement
- [Solved] SyntaxError: Invalid regular expression: invalid group specifier name
- JS bug Log Uncaught TypeError: Cannot read property ‘previoustSibling‘ of null
- [Solved] Uncaught SyntaxError: Unexpected token ‘<‘
- [Solved] Vue Route Error: Uncaught TypeError: (0 , vue__WEBPACK_IMPORTED_MODULE_42__.defineComponent) is not a function
- [Solved] Uncaught SyntaxError: The requested module does not provide an export named
- JS async await Error: Uncaught SyntaxError: await is only valid in async functions and the top level bodies of modules
- [Solved] electron Error: Uncaught TypeError: Cannot read property ‘BrowserWindow‘ of undefined
- [Solved] Uni.createintersectionobserver Error: Uncaught TypeError: Cannot read property ‘bottom’ of null
- [Solved] VUE D:\project\vueProject\vue-02\src\components\hello.vue 5:5 error Parsing error: x-invalid-end-tag
- Vue cannot read property ‘xxx’ of undefined solutions
- Vue Error: Uncaught (in promise) NavigationDuplicated: Avoided redundant navigation to current location
- How to solve Uncaught (in promise) error in VUE?
- Vue Error: error in mounted hook: TypeError: invalid src type