質問失礼いたします。
以下のように、symbolImgItemのキーの値にimgタグを入れ、v-htmlで画像を表示するような事をしたいのですが、moutedをもう少しシンプルに書きたいのですが、for文などでいい方法は無いでしょうか。
html
1<div class="panel_item"> 2 <input id="symbol01" type="radio" v-model.number="b" value="1"> 3 <label class="radio-inline" for="symbol01"> 4 <div class="img_wrapper" v-html="symbolImgItem.symbolImg01"></div> 5 </label> 6 <a href="" @click.prevent="modalNum = 0;modalAction($event);modalSymbolContent($event)" class="btn btn_small btn_standard02 btn_center modal_btn">詳細を見る</a> 7</div> 8<div class="panel_item"> 9 <input id="symbol02" type="radio" v-model.number="b" value="2"> 10 <label class="radio-inline" for="symbol02"> 11 <div class="img_wrapper" v-html="symbolImgItem.symbolImg02"></div> 12 </label> 13 <a href="" @click.prevent="modalNum = 1;modalAction($event);modalSymbolContent($event)" class="btn btn_small btn_standard02 btn_center modal_btn">詳細を見る</a> 14</div> 15コード
vue
1var vm = new Vue({ 2 el: "#app", 3 data: { 4 symbolImgItem: { 5 symbolImg01: null, 6 symbolImg02: null, 7 symbolImg03: null, 8 symbolImg04: null, 9 symbolImg05: null, 10 symbolImg06: null, 11 symbolImg07: null 12 }, 13 symbolImg: [ 14 { 15 pass: 'img/No1.jpg', 16 id: 'symbol01_item' 17 }, 18 { 19 pass: 'img/No2.jpg', 20 id: 'symbol03_item' 21 }, 22 { 23 pass: 'img/No3.jpg', 24 id: 'symbol03_item' 25 }, 26 { 27 pass: 'img/No4.jpg', 28 id: 'symbol04_item' 29 }, 30 { 31 pass: 'img/No5.jpg', 32 id: 'symbol05_item' 33 }, 34 { 35 pass: 'img/No6.jpg', 36 id: 'symbol06_item' 37 }, 38 { 39 pass: 'img/No7.jpg', 40 id: 'symbol07_item' 41 } 42 ] 43 }, 44 mounted: function () { 45 this.symbolImgItem.symbolImg01 = '<img src="' + this.symbolImg[0].pass + '" alt="" id="' + this.symbolImg[0].id + '">'; 46 this.symbolImgItem.symbolImg02 = '<img src="' + this.symbolImg[1].pass + '" alt="" id="' + this.symbolImg[1].id + '">'; 47 this.symbolImgItem.symbolImg03 = '<img src="' + this.symbolImg[2].pass + '" alt="" id="' + this.symbolImg[2].id + '">'; 48 this.symbolImgItem.symbolImg04 = '<img src="' + this.symbolImg[3].pass + '" alt="" id="' + this.symbolImg[3].id + '">'; 49 this.symbolImgItem.symbolImg05 = '<img src="' + this.symbolImg[4].pass + '" alt="" id="' + this.symbolImg[4].id + '">'; 50 this.symbolImgItem.symbolImg06 = '<img src="' + this.symbolImg[5].pass + '" alt="" id="' + this.symbolImg[5].id + '">'; 51 this.symbolImgItem.symbolImg07 = '<img src="' + this.symbolImg[6].pass + '" alt="" id="' + this.symbolImg[6].id + '">'; 52 } 53 });
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2019/06/07 08:55