vue.jsの data
で定義した変数を、vueの mounted
で定義した d3.json
内で呼び出したいのですが、よくわからないです。
下のコードようにクリックした際に、 active = true
にしたいです
js
1export default { 2 data() { 3 return { 4 active: false, 5 } 6 7 }, 8 mounted() { 9 var svg = d3.select(this.$el).append("svg") 10 var width = +svg.attr('width', width * 10); 11 var height = +svg.attr('height', height * 100); 12 var path = geoPath(); 13 var title = svg.append("text") 14 var projection = geoCylindricalStereographic() 15 var path = d3.geo.path().projection(projection); 16 var graticule = d3.geo.graticule(); 17 d3.json("static/readme-world-110m.json", function(error, world) { 18 if (error) throw error; 19 20 var countries = topojson.feature(world, world.objects.countries).features, 21 i = -1, 22 n = topojson.neighbors(world.objects.countries.geometries); 23 24 var country = svg.selectAll(".country") 25 .data(countries) 26 .enter().insert("path", ".graticule") 27 .attr("class", "country") 28 .attr("d", path) 29 .attr("class", "feature") 30 .on("click", click) 31 .style("fill", function(d, i) { return color(d.color = d3.max(n[i], function(n) { return countries[n].color; }) + 1 | 0); }); 32 }) 33 34 function click(d){ 35 console.log(d.id); 36 alert(d.id) 37 } 38 }, 39 methods: { 40 open: function() { 41 this.active = true 42 }, 43 close: function() { 44 this.active = false 45 } 46 }, 47}
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。