vue.js - 如何从 JS 控制台访问 Vue 组件中的变量?

标签 vue.js

我有一个这样的模板:

<template>
  <div>{{hello}}</div>
</template>
<script>
export default {
  data() {
    hello: "Hello World!",
    secret: "The answer is 42"
  }
}
</script>

如何从 Chrome 调试控制台获取和操作 secret 的值?

我已经安装了 Vue 扩展,它允许我查看我的组件并查看变量。我想做的是获取这些变量并对其进行操作。

这可能吗?

最佳答案

Vue.js 论坛上也有类似的讨论。具体来说,SevenLines post on Mar 25 2018阅读:

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:

Example image

关于vue.js - 如何从 JS 控制台访问 Vue 组件中的变量?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51848439/

相关文章:

vue.js - 向子元素添加事件类

vue.js - 如何修复 "This is probably not a problem with npm. There is likely additional logging output above."错误?

javascript - Vue.js 3 : a `v-model` looses reactivity when `data()` converted to `setup()`

javascript - "watch"Vuex模块有可能吗?

javascript - 在名称属性中使用索引并使用 vee 验证自定义错误消息?

vue.js - 已分配计算属性 'name' 但它没有 setter (没有 v-model)

javascript - 使用 Promise 控制 VueJ 中的事件流

vue.js - vuejs属性中的语法 `${k}`是什么?

vue.js - 转到定义不适用于我的项目(vue 和 sass 文件)[visual-studio-code]

javascript - 如何从 Vue.js 中的变量名加载组件?