马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?立即注册
x
vue3父组件调用vue2子组件传参数
1. vue3父组件
- <template>
- <div>
- <child :message="message" />
- <button @click="test">添加车牌号</button>
- </div>
- </template>
-
- <script setup>
- import { ref, onMounted } from 'vue';
- import Child from './Child.vue'; // 确保路径正确
- const id = ref(0);
- const message = ref('');
-
- const test = () => {
- id.value = 1;
- message.value = "皮卡";
- };
- </script>
复制代码 2. vue2子组件`
- <template>
- <div>{{ message }}</div>
- </template>
- <script>
- export default {
- props: ['id','message'],
- data() {
- return {
- message: ''
- }
- },
-
- mounted() {
- this.message = this.$props.message;
-
- }
- }
- </script>
复制代码 免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。 |