link137 link138 link139 link140 link141 link142 link143 link144 link145 link146 link147 link148 link149 link150 link151 link152 link153 link154 link155 link156 link157 link158 link159 link160 link161 link162 link163 link164 link165 link166 link167 link168 link169 link170 link171 link172 link173 link174 link175 link176 link177 link178 link179 link180 link181 link182 link183 link184 link185 link186 link187 link188 link189 link190 link191 link192 link193 link194 link195 link196 link197 link198 link199 link200 link201 link202 link203 link204 link205 link206 link207 link208 link209 link210 link211 link212 link213 link214 link215 link216 link217 link218 link219 link220 link221 link222 link223 link224 link225 link226 link227 link228 link229 link230 link231 link232 link233 link234 link235 link236 link237 link238 link239 link240 link241 link242 link243 link244 link245 link246 link247 link248 link249 link250 link251 link252 link253 link254 link255 link256 link257 link258 link259 link260 link261 link262 link263 link264 link265 link266 link267 link268 link269 link270 link271 link272 link273

[Vue.js] Data via prop not being displayed

there is managed to get myself slightly confused. there is an app where I can display all user profiles, this component is called all-profiles. An example of this page is

<tr v-for=”profile in profiles.data” :key=”profile.id”>
<td>{ profile.id }</td>
<td>{ profile.user.name }</td>
<td>{ profile.created_at }</td>
<td>
<router-link :to=”{ name: user-profile, params: {
id: profile.id }” tag=”a” exact> View Profile
</router-link>
</td>
</tr>

So nothing fancy here, just a simple loop. When you click on the router-link for a specific profile, it takes you to that page, a component called user-profile. I pass the profile id as a parameter.

So in the user-profile component, I display information about that profile. Most of the work is done in the created function

created() {
let vm = this;

let url = `/api/profile/${this.$route.params.id}`;
axios.get(url)
.then(response => {
this.profile = response.data;
this.fileName = response.data.file_path;
return d3.json(response.data.file_path);
}).then(data => {
//display some data
}).catch(err => {
//log error
});
}

So I firstly make an axios call to pull information about that profile. Each profile has a file_path which contains some processed data, in JSON form. I load this using d3 and display the data. This also works fine, no issues here. The issue is on this page however, within the template tags, I load another component which needs the file_path in order to display some data
within the file in the form of a chart. So there is

<barchart :file-name = this.fileName></barchart>

Now if I output fileName within the user-profile page, I can see it is correct. Now in the barchart component, there is the prop

props: {
fileName: {
type: String,
required: true
}
}

And then in the created function, I have

created() {
console.log(this.fileName);
}

So that should output the fileName when passing via the prop, but it currently outputs nothing. I used to have this working, but I was using route parameters, and wanted to switch things to props instead.

there is a feeling that maybe the barchart component is loaded before the fileName is properly set?

when not sure, is there anything obvious that might cause nothing to get outputted?

Thanks

Solution :

Is it just as simple as: you are using “:filename = this.filename” in the template? The ‘this’ seems to be out of place?