定义在default 外的变量, 全局变量可以使用
<template>
<div>
<div :class="someVarData"/> <!-- This is Ok -->
<div :class="someVar"/> <!-- This is not Ok -->
</div>
<template>
<script>
const someVar = "blah";
export default {
data() {
return {
someVarData: "blahData",
};
},
mounted() {
const el = document.getElementById('myId');
el.addEventListener('mouseenter', function () {
console.log(someVar); // This is Ok
console.log(this.someVarData); // This is not Ok
});
},
beforeRouteEnter() { // <--- Vue-router's Navigation guard
console.log(someVar); // This is Ok
console.log(this.someVarData); // This is not Ok
},
</script>
定义在default 内, 和 data外的数据
好像是computed 计算.
return 内的应该是渲染
网友评论