sunny123456

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::

vue基本知识回顾 | this.$http.get 和 this.$http.post传参 / created与mounted区别 / 富文本解析
https://blog.csdn.net/feng2qing/article/details/126241834

vue使用this.$http.getthis.$http.post传参

get传参方式

this.$http.get('http://localhost:8080/testApi', {
  params: {
    name: "张三",
    phone: "13888888888"
   }
}).then((res) => {
  console.log('请求完成')
});
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8

post传参方式

this.$http.get('http://localhost:8080/testApi', {
    name: "张三",
    phone: "13888888888"
}).then((res) => {
  console.log('请求完成')
});
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6

vuecreatedmounted区别

created:在模板渲染成html前调用,即通常初始化某些属性值,然后再渲染成视图。一般数据请求后赋值操作在次执行。

mounted:在模板渲染成html后调用,通常是初始化页面完成后,再对html的dom节点进行一些需要的操作。


vue富文本解析

data() {
    return {
      content: [], //保存后端请求的富文本
    };
},
created() {
	// 富文本请求并赋值
    this.$http.post('http://localhost:8080/contentApi', {}).then((res) => {
      if (res.data.code == 100) {
        this.content = res.data.content;
      }
    });
},
// 富文本解析展示
<p v-html="content"></p>
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17

vue项目运行

num run dev
//在项目为文件夹下运行该命令
  • 1
  • 2

vue项目打包

num run build
//在项目为文件夹下运行该命令
  • 1
  • 2
posted on 2023-01-18 10:45  sunny123456  阅读(2135)  评论(0编辑  收藏  举报