• vue-其他


    vue-resource

    // 2.1 导入 vue-resource
    import VueResource from 'vue-resource'
    // 2.2 安装 vue-resource
    Vue.use(VueResource)
    // 设置请求的根路径
    Vue.http.options.root = 'http://vue.studyit.io';
    // 全局设置 post 时候表单数据格式组织形式   application/x-www-form-urlencoded
    Vue.http.options.emulateJSON = true;
    

    moment

    // 导入格式化时间的插件
    import moment from 'moment'
    // 定义全局的过滤器
    Vue.filter('dateFormat', function (dataStr, pattern = "YYYY-MM-DD HH:mm:ss") {
      return moment(dataStr).format(pattern)
    })
    
    

    preview

    // 安装 图片预览插件
    import VuePreview from 'vue-preview'
    Vue.use(VuePreview)
    

    缩略图使用实例

    <template>
      <div class="photoinfo-container">
        <h3>{{ photoinfo.title }}</h3>
        <p class="subtitle">
          <span>发表时间:{{ photoinfo.add_time | dateFormat }}</span>
          <span>点击:{{ photoinfo.click }}次</span>
        </p>
    
        <hr>
    
        <!-- 缩略图区域 -->
        <div class="thumbs">
          <img class="preview-img" v-for="(item, index) in list" :src="item.src" height="100" @click="$preview.open(index, list)" :key="item.src">
        </div>
    
        <!-- 图片内容区域 -->
        <div class="content" v-html="photoinfo.content"></div>
    
        <!-- 放置一个现成的 评论子组件 -->
        <cmt-box :id="id"></cmt-box>
      </div>
    </template>
    
    <script>
    // 1. 导入评论子组件
    import comment from "../subcomponents/comment.vue";
    
    export default {
      data() {
        return {
          id: this.$route.params.id, // 从路由中获取到的 图片Id
          photoinfo: {}, // 图片详情
          list: [] // 缩略图的数组
        };
      },
      created() {
        this.getPhotoInfo();
        this.getThumbs();
      },
      methods: {
        getPhotoInfo() {
          // 获取图片的详情
          this.$http.get("api/getimageInfo/" + this.id).then(result => {
            if (result.body.status === 0) {
              this.photoinfo = result.body.message[0];
            }
          });
        },
        getThumbs() {
          // 获取缩略图
          this.$http.get("api/getthumimages/" + this.id).then(result => {
            if (result.body.status === 0) {
              // 循环每个图片数据,补全图片的宽和高
              result.body.message.forEach(item => {
                item.w = 600;
                item.h = 400;
              });
              // 把完整的数据保存到 list 中
              this.list = result.body.message;
            }
          });
        }
      },
      components: {
        // 注册 评论子组件
        "cmt-box": comment
      }
    };
    </script>
    
    <style lang="scss" scoped>
    .photoinfo-container {
      padding: 3px;
      h3 {
        color: #26a2ff;
        font-size: 15px;
        text-align: center;
        margin: 15px 0;
      }
      .subtitle {
        display: flex;
        justify-content: space-between;
        font-size: 13px;
      }
    
      .content {
        font-size: 13px;
        line-height: 30px;
      }
    
      .thumbs{
        img{
          margin: 10px;
          box-shadow: 0 0 8px #999;
        }
      }
    }
    </style>
    
    

    图片懒加载(muit提供)

    <!-- 图片列表区域 -->
        <ul class="photo-list">
          <router-link v-for="item in list" :key="item.id" :to="'/home/photoinfo/' + item.id" tag="li">
            <img v-lazy="item.img_url">
            <div class="info">
              <h1 class="info-title">{{ item.title }}</h1>
              <div class="info-body">{{ item.zhaiyao }}</div>
            </div>
          </router-link>
        </ul>
    
  • 相关阅读:
    遍历Newtonsoft.Json.Linq.JObject
    JSON中JObject和JArray,JValue序列化(Linq)
    RabbitMQ学习系列二:.net 环境下 C#代码使用 RabbitMQ 消息队列
    RabbitMQ学习系列三:.net 环境下 C#代码订阅 RabbitMQ 消息并处理
    RabbitMQ学习系列一:windows下安装RabbitMQ服务
    红帽企业版Linux成为Linux下的.NET Core的参考平台
    LINUX下SYN FLOOD攻击及LINUX下SYN攻防简述
    Linux下tar命令的各种参数选项和他们的作用整理
    异常值监测的方法 Tukey test
    Git如何回滚代码?
  • 原文地址:https://www.cnblogs.com/ygjzs/p/12042128.html
Copyright © 2020-2023  润新知