英文:
Finding variable names in vue components
问题
我有一个程序中的变量名列表
我想查看我的Vue组件中所有使用了哪些组件中的变量。
例如:
let x = ['test_one', 'test_two'];
查找所有组件中是否使用了某些内容
// Example.vue
<template>
{{ x }}
</template>
<script setup>
const test_one = ref('hello');
const x = ref('abcd');
</script>
查找 test_one
是否存在于 Example.vue
中
查找 test_two
是否存在于 Example.vue
中
您知道我可以查找组件中的变量的方法吗?
英文:
I have a list of variable names in my program
I want to look in all my components in vue and see which component each variable is used in.
For example :
let x = ['test_one', 'test_two'];
find in all components for uses someone
// Example.vue
<template>
{{ x }}
</template>
<script setup>
const test_one = ref('hello');
const x = ref('abcd');
</script>
find test_one
exists in Example.vue
find test_two
exists in Example.vue
Do you know of a way I can look for variables in my components?
答案1
得分: 1
如果我理解正确,您可以在子组件中使用 defineExpose
宏,然后在父组件中对该组件使用一个 ref:
Example.vue
<template>
{{ x }}
</template>
<script setup>
import {ref} from 'vue'
const test_one = ref('hello');
const x = ref('abcd');
defineExpose({test_one,x})
</script>
在父组件中:
<script setup>
import { ref } from 'vue'
import Example from './Example.vue'
const example = ref()
console.log("Example value: ", example.value)
</script>
<template>
<Example ref="example"/>
</template>
英文:
If I understood correctly, you can use defineExpose
macro in child component, then use a ref on that component in parent one :
Example.vue
<template>
{{ x }}
</template>
<script setup>
import {ref} from 'vue'
const test_one = ref('hello');
const x = ref('abcd');
defineExpose({test_one,x})
</script>
in parent component :
<script setup>
import { ref } from 'vue'
import Example from './Example.vue'
const example =ref()
console.log("Example value: ",example.value)
</script>
<template>
<Example ref="example"/>
</template>
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论