お世話になります。Vue.jsとaxiosを用いてjsonファイルからリストを取り出し、フィルタリングしてリストを表示するコンポーネントを作成しています。
HTML
1<sample val="a"></sample>
このように書いてvalの値でフィルタリングをしたいと思っております。
javascript
1<template> 2<div> 3 <div> 4 <ul> 5 <li v-for="list in lists" v-bind:key="list.id"> 6 <a :href="`/word/`+list.ehead+`/`+list.eword+`.html`">{{list.eword}}({{list.jword}})</a> 7 </li> 8 </ul> 9 </div> 10</div> 11</div> 12</template> 13<script> 14import axios from 'axios' 15export default { 16props: ["val"], 17 data() { 18 return { 19 fulllists: [], 20 } 21 }, 22 created: function() { 23 axios.get('/list.json').then(function(response) { 24 this.fulllists = response.data 25 }.bind(this)).catch(function(e) { 26 console.error(e) 27 }) 28}, 29computed: { 30 scope: function(){ 31 return this.val 32 }, 33 lists: function() { 34 return this.fulllists.filter(function(i) { 35 console.log(i) 36 return i.ehead === 'scope' 37 }) 38 } 39}, 40} 41 42</script>
json
1[ 2 { 3 "id": 1, 4 "eword": "abalone", 5 "jword": "アワビ", 6 "ehead": "a", 7 "jhead": "あ", 8 "ecat": "food", 9 "jcat": "食物" 10 }, 11 { 12 "id": 1013, 13 "eword": "dystopia", 14 "jword": "ディスコピア", 15 "ehead": "d", 16 "jhead": "て", 17 "ecat": "place", 18 "jcat": "場所" 19 } 20]
vueのツールで確認するとval="a"となっているときはscopeがaになっているのですが表示されません。
ご教授のほどよろしくお願い申し上げます。
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。