子コンポーネント内メソッドのforEach
でprops
ないのデータを取得したいのですが、this.template.width
などをログで吐かせてもundefindになってしまいます。
このような時にforEach
内でprops
の変数を取得する方法を教えてください。
<template> </template> <script> export default { props: { template: { type: Object, default: () => ({ width: "", height: "", layers: [] }) } }, mounted: function() { }, methods: { getTemplates() { let templates = [ { id: 1, width: 300, height: 400, layers: [ {"type":"logo", "width":50, "height":50, "x_position": 10, "y_position": 10, "z_index": 1}, {"type":"image", "width":300, "height":200, "x_position": 100, "y_position": 80, "z_index": 0} ] }, ] let response = JSON.stringify(templates) return JSON.parse(response); }, replaceTemplates() { let oldTemplates = this.getTemplates() let templates = [] oldTemplates.forEach(function (templateSettings) { //this.template.width と this.template.height が undefind になってしまう if(templateSettings.width == this.template.width && templateSettings.height == this.template.height) { templates.append(template) } }) }, } } </script>
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2018/12/13 08:52