当前位置:   article > 正文

Vue:实现table表格置顶_vue toptable

vue toptable

老大让做vue项目,可是我对vue还不熟可怜好吧,抓紧时间学习,记录

此处省略css

  1. <table id="toptable" >
  2. <thead>
  3. <tr>
  4. <th>序号</th>
  5. <th>显示顺序</th>
  6. <th>景区名称</th>
  7. <th>景区地址</th>
  8. <th width="230px"></th>
  9. </tr>
  10. </thead>
  11. <tbody>
  12. <tr v-for="(item,index) of dataList">
  13. <td v-text="item.code"></td>
  14. <td v-text="index+1"></td>
  15. <td v-text="item.name"></td>
  16. <td v-text="item.region"></td>
  17. <td style="text-align: right;">
  18. <button v-if="index !==0" @click="getTop(index)">置顶</button>
  19.  <button @click="delData(index)">删除</button>
  20. </td>
  21. </tr>
  22. </tbody>
  23. </table>
  1. <script>
  2. var vtable=new Vue({
  3. el:"#toptable",
  4. data:{
  5. dataList:[]
  6. },
  7. mounted(){
  8. this.showData();
  9. },
  10. methods:{
  11. showData () {
  12. axios.get("arealist.json").then(response=>{
  13. for(let i=0;i<response.data.length;i++){
  14. vtable.dataList.push(response.data[i]);
  15. }
  16. })
  17. },
  18. deleteData(index){
  19. if(!confirm("您确定要删除此景区吗?")){
  20. return false;
  21. }
  22. vtable.dataList.splice(index,1);
  23. },
  24. getTop(index){
  25. var returnTop=vp.dataList[index];
  26. vtable.dataList.splice(index,1)
  27. vtable.dataList.unshift(returnTop);
  28. }
  29. }
  30. })
  31. </script>
  1. [
  2. {
  3. "name":"狼牙山景区",
  4. "code":"00123545",
  5. "region":"保定 易县"
  6. },{
  7. "name":"白洋淀",
  8. "code":"00343445",
  9. "region":"保定 白洋淀"
  10. },{
  11. "name":"野山坡",
  12. "code":"00123598",
  13. "region":"保定 涞水"
  14. }
  15. ]

置顶前:


置顶后:


声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/小小林熬夜学编程/article/detail/223989
推荐阅读
相关标签
  

闽ICP备14008679号