Home > front end >  O vue. Js, how to create a function
O vue. Js, how to create a function

Time:09-17




<meta charset="UTF-8">
Books management system management system & lt;/title> <br/></head> <br/><body> <br/><The script type="text/javascript" SRC="https://bbs.csdn.net/topics/js/vue.js" & gt; </script> <br/><Div id="app" & gt; <br/><H1 & gt; {{message}} & lt;/h1 & gt; <br/>Book number: & lt; Input type="text" v - model="a" & gt; <br> <br/>Book name: & lt; Input type="text" v - model="b" & gt; <br> <br/>Book prices: & lt; Input type="text" v - model="c" & gt; <br> <br/>Press: & lt; The select v - model="d" & gt; <br/><The option value="https://bbs.csdn.net/topics/text" & gt; Higher education press & lt;/option> <br/><The option value="https://bbs.csdn.net/topics/text" & gt; People's posts and telecommunications press & lt;/option> <br/><The option value="https://bbs.csdn.net/topics/text" & gt; Tsinghua university press & lt;/option> <br/></select> <br/><br> <br/><The button @ click="create" & gt; Add & lt;/button> <The button @ click="resetLoginForm" & gt; Reset & lt;/button> <br/><br> <br/><Table> <br/><Thead> <br/><Tr> <br/><Th> Book number & lt;/th> <br/><Th> The book name & lt;/th> <br/><Th> Book prices & lt;/th> <br/><Th> Press & lt;/th> <br/><Th> Operation & lt;/th> <br/></tr> <br/><br/><Tr v - for="p in prop" & gt; <br/><Td> {{p.i d}} & lt;/td> <br/><Td> {{p.n ame}} & lt;/td> <br/><Td> {{p.p rice}} & lt;/td> <br/><Td> {{p.c bs}} & lt;/td> <br/><Td> <The button @ click="delect" & gt; Delete & lt;/button> <The button @ click="amend" & gt; Modify & lt;/button> </td> <br/></tr> <br/><br/><br/></thead> <br/></table> <br/></div> <br/><script> <br/>Var=new vm Vue ({<br/>El: "# app," <br/>Data: {<br/>The message: "the books management system management system", <br/>Prop: [{id: "1", the name: "vue. Js," price: "45", CBS: "high press"}, <br/>{id: "2", the name: "the MySQL database," price: "48," CBS: "people's posts and telecommunications publishing house"}, <br/>{id: "3", the name: "Java foundation," price: "35", CBS: "tsinghua university press"} <br/>], <br/>A: "' <br/>B: "' <br/>C: "' <br/>D: "' <br/><br/>}, <br/>Methods: {<br/>Create: function () {<br/>This. Prop. Push ({id: enclosing a, name: this. B, price: this. C, CBS: this. D}) <br/>}, <br/>//resetLoginForm: function () {<br/>//<br/>//this. $refs. LoginFormRef. ResetFields () <br/>//}, <br/>Delect: function (index) {<br/>This. Prop. Splice (index, 1); <br/>}, <br/>//amend: the function () {<br/>//this. Prop <br/>//} <br/>} <br/><br/>}) <br/></script> <br/></body> <br/></html> <br/>Those comments up is I can't function, the other two are added and removed, I want to ask about how to create your own want to function, <br/>And reset function of the input box, and modify the function, thank you<p class="article - content rp"> CodePudding user response: </p>Great god answer, thank you<p class="article - content rp"> CodePudding user response: </p>In the methods directly write <br/><pre> <br/>The add () {<br/>Write the content here <br/>} <br/>Del () {<br/>Write the content <br/>} <br/></pre> <br/>Don't need a colon:<p class="article - content rp"> CodePudding user response: </p>Methods defined in VUE instantiate objects <br/>Reference: https://www.runoob.com/vue2/vue-examples.html <br/><br/>Simple examples are as follows: <br/><Div id="main" & gt; <br/><br/><! - active menu style for the active class - & gt; <br/><! - in order to prevent links when click jump, we use the "prevent" modifier (short for the preventDefault), - & gt; <br/><br/><Nav v - bind: v - on: click. Prevent> <br/><br/><! - when the link by clicking on the menu, we call the makeActive method, this method is created in the Vue instance, - & gt; <br/><br/><A href="https://bbs.csdn.net/topics/#" v - on: click="<span style=" color: # FF0000;"> <strong> makeActive </strong> </span> (' home ') "& gt; Home</a> <br/><A href="https://bbs.csdn.net/topics/#" v - on: click="makeActive (' projects')" & gt; Projects</a> <br/><A href="https://bbs.csdn.net/topics/#" v - on: click="makeActive (' services')" & gt; Services</a> <br/><A href="https://bbs.csdn.net/topics/#" v - on: click="makeActive (' contact ')" & gt; Contact</a> <br/></nav> <br/><br/><! - the following "active" variable will automatically transform according to the currently selected value - & gt; <br/><br/><p> You select the & lt; B> {{active}} menu & lt;/b> </p> <br/></div> <br/><br/><script> <br/>//create a new Vue instance <br/>Var demo=new Vue ({<br/>//DOM elements, mount view model <br/>El: '# main', <br/><br/>//custom properties, and set the initial value <br/>Data: {<br/>Active: 'home' <br/>}, <br/><br/>//click menu functions used <br/>Methods: {<br/><span style="color: # FF0000;"> <strong> makeActive </strong> </span> : function (item) {<br/>//model change, the view will automatically update <br/>this.active=item; <br/>} <br/>} <br/>}); <br/></script> </div> <div class="th_page th_page_color"></div> <div class="umCopyright"> <p>Page link:<a href="/frontend/5351.html" target="_blank" style="color:#999">https//www.codepudding.com/frontend/5351.html</a></p> </div> <div class="detail-arr"> <div class="detail-arr-left">Prev:<a href='/frontend/5350.html'>Mobile terminal project in vue. Js and optimal which UI library building project?</a></div> <div class="detail-arr-right">Next:<a href='/frontend/5352.html'>Consult with the certificate</a></div> </div> </div> </div> </div> </div> <div class="container th_top"> <div class="row"> <div class="col-md-12"> <div class="hot-tags neitags"> <ul> <li><i class="iconfont icon-x-tags"></i> Tags:  </li> <a href='/e/tags/?tagname=HTML5' target='_blank'>HTML5</a> </ul> </div> </div> </div> </div> <div class="container th_top"> <div class="row"> <div class="col-md-12"> <div class="xiangguan"> <ul class="msg msghead"> <li class="tbname">Related</li> </ul> <ul> </ul> </div> </div> </div> </div> <div class="container th_top"> <div class="row"> <div class="col-md-12"> <div class="flinks"> <ul> <li><i class="iconfont icon-x-tags"></i> Links:  </li> <li class="liflinks"><a target="_blank" href="/" title="CodePudding">CodePudding</a></li> </ul> </div> </div> </div> </div> <div class="footer"> <p><span style="font-size:16px;color:#666;font-weight: bold">About Us:</span>  <a href="https://www.codepudding.com/contact.html">Contact Us</a>      <a href="https://www.codepudding.com/service.html">Terms of Service</a>      <a href="https://www.codepudding.com/privacy.html"> Privacy Policy</a></p> <p class="foot_info">Copyright © 2010-2023,Powered By <a href="/" target="_blank">CodePudding</a> </p> </div> <script type="text/javascript" src="/skin/code/tianhu.js"></script> </body></html>