我(在您的帮助下)创建了一个下拉菜单,当使用 Vue 单击时会更改文本,但我希望该图像也出现,但我的代码不起作用,我试过这个:
<div class="relative">
<!-- Dropdown toggle button -->
<button
@click="show = !show"
class="flex items-center text-gray-500 rounded-md"
>
<span class="inline-flex">
{{selectedImg??''}}
{{selectedLang??'English'}}</span>
</button>
<!-- Dropdown menu -->
<div
v-show="show"
class="
absolute right-0 py-2
mt-5 rounded-md shadow-xl w-36 bg-white
"
>
<router-link
to="/"
@click="selectedLang='English'"
class="
inline-flex w-full px-4 py-2 text-sm text-gray-500
hover:bg-indigo-100 hover:text-indigo-600
"
>
<img src="../Assets/Img/en.png" alt="" class="w-6 h-4 mr-2" @click="selectedImg='English'">
English
</router-link>
<router-link
to="/"
@click="selectedLang='French'"
class="
inline-flex w-full px-4 py-2
text-sm text-gray-500 hover:bg-indigo-100 hover:text-indigo-600
"
>
-----------------------
data() {
return {
show:false,
selectedLang:null,
selectedImg:null
};
},
文本正常更改,但 img 没有任何反应。