简体   繁体   English

如何使用单选按钮选择Vue上的图像?

[英]How can I select images on vue using radio buttons?

I want to create with vue.js a radio button (bootstrap) where I can select the image to visualize. 我想使用vue.js创建一个单选按钮(引导程序),从中可以选择要可视化的图像。 I created 3 buttons for 3 images but I can't connect them (of course the previous image must disappear). 我为3张图片创建了3个按钮,但无法连接它们(当然,前一张图片必须消失)。

<template>
  <b-container>
    <b-row>
      <b-col>
        <b-form-group label="Map to visualize">
          <b-form-checkbox-group
            v-model="map.value"
            :options="map.options"
            name="buttonsMap"
            buttons
          ></b-form-checkbox-group>
        </b-form-group>
      </b-col>
    </b-row>
    <b-row class="map">
      <b-col cols="9">
        <h3>Map</h3>

        <div id="app">
          <img :src="require('./image/Map1.png')" height="400" />
        </div>
      </b-col>
    </b-row>
  </b-container>
</template>

<script>
export default {
  name: 'Rad',
  data() {
    return {
      map: {
        value: 'Map1',
        options: ['Map1', 'Map2', 'Map3'],
      },
    }
  },
}
</script>

This works, but I can only see one map. 这行得通,但我只能看到一张地图。 I wanna add 3 of them connected with the buttons. 我想添加其中3个与按钮相连的按钮。

I believe your img src must include a dynamic value for the different img paths: 我相信您的img src必须包含不同img路径的动态值:

<div id="app">
  <img :src="'require(./image/' + map.value + '.png)'" height="400">
</div>

here is a Demo : codepen 这是一个演示: codepen

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM