0

How should one refer to the value set up within an object passed to v-bind to display it?

Example:

<p v-bind="{id: 'myId'}">{{ /*what to state here to have 'myId' displayed?*/ }}</p>
AbreQueVoy
  • 1,748
  • 8
  • 31
  • 52

1 Answers1

0

The <p> is not a child component, everything here is all in the same scope. You cannot refer to its attributes from its contents. As in Bert's example, you simply have to put what you want in both places.

If you want to use a variable for the id and for the contents, you can do that, but you have to explicitly put it in both places:

<p :id="myIdVariable">{{myIdVariable}}</p>
Roy J
  • 42,522
  • 10
  • 78
  • 102
  • OK, Gentlemen, I see I didn't give you the full context :-) In the real-life code the id is assigned to the HTML tag as an 'id' parameter (

    ). I thought setting it up through v-bind will give me the access from inside of the "p" tag and I could read that id's value. What I want is getting that id and further processing it using a method. Any thoughts how to achieve this?
    – AbreQueVoy Jul 06 '17 at 19:48
  • My answer says that you cannot do that. In particular, "You cannot refer to its attributes from its contents." You could make a component, though. – Roy J Jul 06 '17 at 21:12
  • Updated answer, though I can't tell whether I'm just saying something that is obvious to you. – Roy J Jul 07 '17 at 01:43
  • Thanks. I'll try to build something on top of this. If no success, I have an idea on how to achieve my goal using jQuery. – AbreQueVoy Jul 07 '17 at 12:49
  • 1
    Be sure you understand [how to make Vue and jQuery play nice](https://stackoverflow.com/a/43255516/392102) – Roy J Jul 07 '17 at 13:55