如何从 JS 控制台访问 Vue 组件中的变量? [英] How to access variables in a Vue component from the JS Console?
问题描述
我有一个这样的模板:
<div>{{hello}}</div></模板><脚本>导出默认{数据() {你好:世界你好!",秘密:答案是42"}}
如何从 Chrome 调试控制台获取和操作 secret
的值?
我已经安装了 Vue 扩展,它允许我查看我的组件并查看变量.我想做的是获取这些变量并对其进行操作.
这可能吗?
Vue.js 论坛上也有类似的讨论.具体来说,
I have a template like this:
<template>
<div>{{hello}}</div>
</template>
<script>
export default {
data() {
hello: "Hello World!",
secret: "The answer is 42"
}
}
</script>
How can I get, and manipulate the value of secret
from the Chrome debugging console?
I have installed the Vue extension which allows me to look at my component and see the variables. What I would like to do is to get these variables and manipulate them.
Is this possible?
There is a similar discussion on the Vue.js forum. Specifically, SevenLines post on Mar 25 2018 reads:
Update from 2018. If you use vue-devtools, you can access Vue from console by selecting desired component, and then accessing it through $vm variable. Check the image with example:
这篇关于如何从 JS 控制台访问 Vue 组件中的变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!