[英]Import default in Vue component not definied in DevTools console
Simple data example, constants.js简单数据示例,constants.js
export default {
name: "John Smith",
age: 10
};
Import it on the Vue component, which renders correctly.将其导入正确呈现的 Vue 组件。 But if I use the DevTools and type
c
in the console... c
is undefined.但是,如果我使用 DevTools 并在控制台中键入
c
... c
未定义。
import c from "../constants/constants.js";
export default {
name: "HelloWorld",
computed: {
myName() {
debugger;
// In DevTools, console... c is undefined
// even though this clearly works
return c.name;
},
},
};
I don't understand why?我不明白为什么?
Example: https://codesandbox.io/s/constantsimportreference-ud0d3e?file=/src/components/HelloWorld.vue:90-341示例: https://codesandbox.io/s/constantsimportreference-ud0d3e?file=/src/components/HelloWorld.vue:90-341
Modules are not exposed to the global scope ( window
) when transpiled.转译时,模块不会暴露给全局 scope (
window
)。
If you really want to expose c
in DevTools you'd have to do window.c = c
;如果你真的想在
c
中公开 c 你必须做window.c = c
; Be careful when referencing window as this will break when rendering server side or prerendering as window
does not exist.引用 window 时要小心,因为这会在渲染服务器端或预渲染时中断,因为
window
不存在。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.