找回密码
 立即注册
查看: 2|回复: 0

6,VUE案例

[复制链接]

261

主题

6

精华

265

金币

技术维护QQ:515138

积分
571
发表于 昨天 08:15 | 显示全部楼层 |阅读模式

1.jpg

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4.     <meta charset="UTF-8">
  5.     <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6.     <title>Document</title>
  7. </head>
  8. <body>
  9.     <div id="app">
  10.         文章分类: <input type="text" v-model="searchConditions.category">
  11.         发布状态: <input type="text"  v-model="searchConditions.state">
  12.         <button v-on:click="search">搜索</button>
  13.         <br />
  14.         <br />
  15.         <table border="1 solid" colspa="0" cellspacing="0">
  16.             <tr>
  17.                 <th>文章标题</th>
  18.                 <th>分类</th>
  19.                 <th>发表时间</th>
  20.                 <th>状态</th>
  21.                 <th>操作</th>
  22.             </tr>
  23.             <tr v-for="(article,index) in articleList">
  24.                 <td>{{article.title}}</td>
  25.                 <td>{{article.category}}</td>
  26.                 <td>{{article.time}}</td>
  27.                 <td>{{article.state}}</td>
  28.                 <td>
  29.                     <button>编辑</button>
  30.                     <button>删除</button>
  31.                 </td>
  32.             </tr>
  33.             <!-- <tr>
  34.                 <td>标题2</td>
  35.                 <td>分类2</td>
  36.                 <td>2000-01-01</td>
  37.                 <td>已发布</td>
  38.                 <td>
  39.                     <button>编辑</button>
  40.                     <button>删除</button>
  41.                 </td>
  42.             </tr>
  43.             <tr>
  44.                 <td>标题3</td>
  45.                 <td>分类3</td>
  46.                 <td>2000-01-01</td>
  47.                 <td>已发布</td>
  48.                 <td>
  49.                     <button>编辑</button>
  50.                     <button>删除</button>
  51.                 </td>
  52.             </tr> -->
  53.         </table>
  54.     </div>
  55.     <!-- 导入axios的js文件 -->
  56.     <sc ript src="https://unpkg.com/axios/dist/axios.min.j s"></script>
  57.     <scr ipt type="module">
  58.         //导入vue模块
  59.         import {createApp} from 'https://unpkg.com/vue@3/dist/vue.esm-browser.j s';
  60.         //创建vue应用实例
  61.         createApp({
  62.             data(){
  63.                 return {
  64.                     articleList:[],
  65.                     searchConditions:{
  66.                         category:'',
  67.                         state:''
  68.                     }
  69.                 }
  70.             },
  71.             methods:{
  72.                 //声明方法
  73.                 search:function(){
  74.                     //发送请求,完成搜索,携带搜索条件
  75.                     axios.get('http://localhost:8080/article/search?category='+this.searchConditions.category+'&state='+this.searchConditions.state)
  76.                     .then(result=>{
  77.                         //成功回调 result.data
  78.                         //把得到的数据赋值给articleList
  79.                         this.articleList=result.data
  80.                     }).catch(err=>{
  81.                         console.log(err);
  82.                     });
  83.                 }
  84.             },
  85.             //钩子函数mounted中,获取所有文章数据
  86.             mounted:function(){
  87.                 //发送异步请求  axios
  88.                 axios.get('http://localhost:8080/article/getAll').then(result=>{
  89.                     //成功回调
  90.                     //console.log(result.data);
  91.                     this.articleList=result.data;
  92.                 }).catch(err=>{
  93.                     //失败回调
  94.                     console.log(err);
  95.                 });
  96.             }
  97.         }).mount('#app');//控制html元素
  98.     </scri pt>
  99. </body>
  100. </html>
复制代码





上一篇:5,Axios对原生的Ajax进行了封装,简化书写,快速开发。
下一篇:7,整站使用Vue(工程化)
网站建设,公众号小程序开发,系统定制,软件App开发,技术维护【联系我们】手机/微信:17817817816 QQ:515138

QQ|Archiver|自丢网 ( 粤ICP备2024252464号-1 )

GMT+8, 2026-3-6 03:50

专注于网站建设,公众号小程序制作,商城小程序,系统定制,软件App开发

【联系我们】手机/微信:17817817816 QQ:515138

快速回复 返回顶部 返回列表