<template> <homeHeader :class='isclicked1' vuale="朋哟"></homeHeader> <homeHeader :class='isclicked2' vuale="哼哼"></homeHeader><!-- 实习兼职 --> <van-nav-bar> <template #right> <van-icon name="search" size="18" /> </template> </van-nav-bar> <!-- 搜索图标 --> <div> <!-- <router-view> <tabHome :tabCard="tabHome"></tabHome> </router-view> --> <!-- 综合、web --> <van-tabs v-model:active="active"> <van-tab title="综合"> <tab></tab> <SZ_Boss_home></SZ_Boss_home> </van-tab> <van-tab title="web"> <tab></tab> <SZ_Boss_home></SZ_Boss_home></van-tab> </van-tabs> </div> </template> <script> /* import tabHome from '../components/tab.vue' / import SZ_Boss_home from './SZ_Boss_home.vue' import homeHeader from '../components/homeHeader.vue' import tab from '../components/tab.vue' export default { components: { homeHeader, / tabHome */ SZ_Boss_home, tab }, data() { return { } }, methods: { } } </script> <style scoped> .top_nav { display: flex; position: absolute; top: 0; left: 0; z-index: 999; } .van-nav-bar { background-image: linear-gradient(to right, rgba(86, 238, 233, 0.24), rgba(230, 144, 168, 0.33)); color: rgb(255, 255, 255); border-bottom: 1px rgba(255, 255, 255, 0.45); } .van-tabs__nav .van-tabs__nav--line { top: 300px; height: 0; } .van-tab { float: right; background-color: rgb(80, 160, 171); } </style>该文件调用了<template> <div class="top_nav" > <input type="button" :class="{'my-button': true, 'active': isClicked1}" value="实习" @click="toggleButton1"> <input type="button" :class="{'my-button': true, 'active': isClicked2}" value="兼职" @click="toggleButton2"> </div> </template> <script> export default { name:'homeHeader', data() { return { isClicked1: true, isClicked2: false, } }, methods: { toggleButton1() { if (this.isClicked1) { return; } this.isClicked1 = true; this.isClicked2 = false; this.$emit('reset-buttons'); }, toggleButton2() { if (this.isClicked2) { return; } this.isClicked1 = false; this.isClicked2 = true; this.$emit('reset-buttons'); } }, props:['tit'] } </script> <style scoped> .my-button { border: none; border-radius: 4px; background-color: #f0f0f000; transition: all 0.2s ease-in-out; cursor: pointer; color: rgb(154, 154, 154); font-size: 16px; } .active { background-color: rgba(51, 51, 51, 0); color: rgb(0, 0, 0); font-size: 26px; } .top_nav input{ float: left; } </style>该子组件,但是为什么value得值不能改变
时间: 2024-04-28 08:23:36 浏览: 9
根据你提供的代码,我注意到 `<homeHeader>` 组件中的 input 标签的 value 属性是通过 props 传递进来的,而且在子组件中没有对它进行修改的方法,所以它的值不能改变。如果你想要修改这个值,可以考虑在父组件中将这个值传递给子组件的 data 中,然后通过子组件的 methods 方法来修改它。这样就可以实现动态修改 value 的值了。
相关问题
<template> <homeHeader :class='isclicked1' vuale="朋哟"></homeHeader> <homeHeader :class='isclicked2' vuale="哼哼"></homeHeader><!-- 实习兼职 --> <van-nav-bar> <template #right> <van-icon name="search" size="18" /> </template> </van-nav-bar> <!-- 搜索图标 --> <div> <!-- <router-view> <tabHome :tabCard="tabHome"></tabHome> </router-view> --> <!-- 综合、web --> <van-tabs v-model:active="active"> <van-tab title="综合"> <tab></tab> <SZ_Boss_home></SZ_Boss_home> </van-tab> <van-tab title="web"> <tab></tab> <SZ_Boss_home></SZ_Boss_home></van-tab> </van-tabs> </div> </template> <script> /* import tabHome from '../components/tab.vue' */ import SZ_Boss_home from './SZ_Boss_home.vue' import homeHeader from '../components/homeHeader.vue' import tab from '../components/tab.vue' export default { components: { homeHeader, /* tabHome */ SZ_Boss_home, tab }, data() { return { } }, methods: { } } </script> <style scoped> .top_nav { display: flex; position: absolute; top: 0; left: 0; z-index: 999; } .van-nav-bar { background-image: linear-gradient(to right, rgba(86, 238, 233, 0.24), rgba(230, 144, 168, 0.33)); color: rgb(255, 255, 255); border-bottom: 1px rgba(255, 255, 255, 0.45); } .van-tabs__nav .van-tabs__nav--line { top: 300px; height: 0; } .van-tab { float: right; background-color: rgb(80, 160, 171); } </style>该文件调用了上述子组件,但是为什么vue值不能改变
从您提供的代码来看,我并未发现Vue值不能改变的问题。但是需要注意的是,在您的父组件中,您使用了:class绑定到props属性上,但是props属性是用于从父组件向子组件传递数据的,:class是用于绑定动态的CSS类的,这两者是不同的。如果您想改变子组件的样式,可以在子组件中定义一个data属性,然后使用:class指令将子组件的class属性绑定到该data属性上,然后在父组件中通过props属性传递数据,从而改变子组件的样式。另外,需要确保父组件中传递的props属性名与子组件中定义的props属性名一致,否则子组件无法接收到传递过来的数据。
<template> <div class="top_nav" v-for="item in tits" :key="item.id"> <input type="button" :class="{'my-button': true, 'active': isClicked1}" value="item.title" @click="toggleButton1"> <input type="button" :class="{'my-button': true, 'active': isClicked2}" value="item.title" @click="toggleButton2"> </div> </template> <script> export default { name:'homeHeader', data() { return { isClicked1: true, isClicked2: false, tits:[], } }, methods: { toggleButton1() { if (this.isClicked1) { return; } this.isClicked1 = true; this.isClicked2 = false; this.$emit('reset-buttons'); }, toggleButton2() { if (this.isClicked2) { return; } this.isClicked1 = false; this.isClicked2 = true; this.$emit('reset-buttons'); } }, props:['tit'] } </script> <style scoped> .my-button { border: none; border-radius: 4px; background-color: #f0f0f000; transition: all 0.2s ease-in-out; cursor: pointer; color: rgb(154, 154, 154); font-size: 16px; } .active { background-color: rgba(51, 51, 51, 0); color: rgb(0, 0, 0); font-size: 26px; } .top_nav input{ float: left; } </style>为什么第三行第四行不能显示
在模板中的第三行和第四行,你使用了 `item.title`,但是没有用双花括号包裹起来,应该写成 `{{item.title}}`。这样才能正确地将 `item.title` 的值渲染到页面上。修改后的代码如下所示:
```
<template>
<div class="top_nav" v-for="item in tits" :key="item.id">
<input type="button" :class="{'my-button': true, 'active': isClicked1}" :value="item.title" @click="toggleButton1">
<input type="button" :class="{'my-button': true, 'active': isClicked2}" :value="item.title" @click="toggleButton2">
</div>
</template>
```
同时,你的 `tits` 数组是空的,所以即使你将 `item.title` 渲染到页面上也不会显示任何内容。你需要在 `data` 中初始化 `tits` 数组,例如:
```
data() {
return {
isClicked1: true,
isClicked2: false,
tits: [
{ id: 1, title: 'Button 1' },
{ id: 2, title: 'Button 2' },
],
};
},
```
这样就能在页面上正确显示按钮了。