A
A
Andrey Lamzin2019-12-11 10:45:10
Vue.js
Andrey Lamzin, 2019-12-11 10:45:10

Vue js how to manage src attribute value if it should be set by php script on page load?

<img src="<?=$imageUrl?>" >
and I want to change the value of the src attribute from the vue js application
v-attr does not work, v-bind cannot be applied.

I forgot to write right away, the image should be displayed normally with javascript disabled.
(We support the old android 2 browser, vuejs does not work in it).

Is there a normal solution?

Looks like no.
Came out like this:
<img ref="imagepreview" src="<?=$imageUrl?>" >

onUploadImage(sImageUrl) {
  this.$refs.imagepreview.setAttribute('src', sImageUrl);
}


Which I don't really like, but there seems to be no other way.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
0
0xD34F, 2019-01-16
@asferot

@click="product.quantity = Math.max(0, product.quantity - 1)"

A
Alexander Loginov-Solonitsyn, 2020-01-20
@Byte255

As an option, you can have an input in which to collect all the data that is given through PHP.
And already in Vue use this data

...
data() {
  return {
    dataFromPhp: null
  }
}
...
created() {
  this.dataFromPhp = JSON.parse(document.getElementById('input-data-to-vue'));
}
...

A
Alex, 2019-12-11
@Kozack Vue.js

<img :src="src" :alt="alt">

{
  data: {
    src: <?=$imageUrl?>,
    alt: <?=$imageAlt?>,
  }
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question