Home > front end >  Axios how to render the dom
Axios how to render the dom

Time:10-06

Background has spread to the console can be seen but how to render what is the way I am a small white thank you for your bosses

CodePudding user response:

If you did not use vue, react, presents such as framework, then directly on the success callback to get the data, take out your want to data, in the place where the
 
Such as: HTML inside & lt; Div & gt; & lt; div> Name: & lt; Span> & lt;/span> & lt;/div> & lt;/div>
So success callback to name
Var HTML=` & lt; div> Name: & lt; Span> The ${res. Data. The name} & lt;/span> & lt;/div> `
To get the results of $(' box '). The HTML (HTML) without jquery document. GetElementsByClass (' box ') [0]. InnerHTML ()

This is probably

CodePudding user response:

(1) the first data () {
Return {
Items: "',//define a stored data variables;
}
}

(2) in the place where you put the data to print to the console that is: the console. The log (res) data); There
Enter this. The items=res. Data;

(3) rendering using v - for start loop v - if control cycles

Example: & lt; Div v - for='(item, index) in the items' v - if=' index & lt; 5 '& gt;//the item is in the definition of a variable, the index page, mean circulation first 5 data shown here
& lt; div> . {{item name}} & lt;/div> Here the name only, for example, you want to see give you specific what packets,
& lt;/div>

OK, now you want to data has been rendered to the page,

I am also just learn to use axios and rendered to the page is not enough in-depth study bosses forgive me just to share personal experience
  •  Tags:  
  • Ajax
  • Related