首页 > 其他分享 >vue基本知识回顾 | this.$http.get 和 this.$http.post传参 / created与mounted区别 / 富文本解析

vue基本知识回顾 | this.$http.get 和 this.$http.post传参 / created与mounted区别 / 富文本解析

时间:2023-01-18 10:55:53浏览次数:63  
标签:传参 vue http created get post

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

标签:传参,vue,http,created,get,post
From: https://www.cnblogs.com/sunny3158/p/17059369.html

相关文章

  • 学习Vuex mutations
     Vuex中store数据改变的唯一方法就是提交 mutations。mutations里面装着一些改变数据方法的集合,这是Vuex设计很重要的一点,就是把处理数据逻辑方法全部放在 mutation......
  • 【ES HTTP-增删改成 01】
    一、数据存储:结构化数据,一般会用二维的表结构来存储,如:mysql等关系型数据库非结构化数据,即无法用关系型数据库存储的数据,如:日志、通讯记录、报表、视频、图片等,一般会把......
  • vue中实现高德 地图定位功能
    index.html<template><divid="app"><divid="container"></div><div><p>经度:{{location.lng}}</p><p>纬度:{{location.lat}}</p>......
  • Web安全入门与靶场实战(9)- 利用Burpsuite拦截HTTP数据
    在Web安全中经常需要对HTTP请求和响应的数据进行拦截,从而来对这些数据做进一步的分析或处理,这就要用到一个非常重要的工具Burpsuite。Burpsuite可谓Web安全的神器,要学习Web......
  • go httptest请求
    packagetestimport("encoding/json""github.com/cookieY/yee""io/ioutil""log""net/http""net/http/httptest""strings")typeCasestruct{Met......
  • vuex详解
    vuex的介绍vuex是vue.js应用程序中的状态管理模式,它是集中式存储管理所有组件的数据状态,vuex解决了多个视图之间的数据交互同步,不需要进行组件连接再传递数据。vuex的5大......
  • vue的基本使用
                                          ......
  • vue打包失败
    如题,vue项目打包输入npmrunbuild报错了  首先本地启动项目npmrundev是能正常跑起来的,看package.json  正确的命令应该是npmrunbuild:prod--report参......
  • vuejs从入门到精通——观察 Vue 实例从创建到销毁的完整生命周期
    观察Vue实例从创建到销毁的完整生命周期一、一个简单的Vue实例代码如下:<!DOCTYPEhtml><html><head><metacharset="utf-8"><title>Vue从入门到精通,https://w......
  • Vue 项目报错:Syntax Error:Unexpected token
    报错ERRORin./node_modules/babel-loader/lib!./node_modules/vue-loader/lib/selector.js?type=script&index=0!./node_modules/element-ui/packages/image/src/image-......