首页 > 其他分享 >[Web] 前端的一些快速启动

[Web] 前端的一些快速启动

时间:2023-02-07 11:55:50浏览次数:38  
标签:Web use formData 启动 res 前端 list js fetch

Vue Quick Start with Vue-CLI

import in html page:

<script type="importmap">
  {
    "imports": {
      "vue": "https://unpkg.com/vue@3/dist/vue.esm-browser.js"
    }
  }
  
</script>


<script type="module">
  import { createApp } from 'vue'
  import MyComponent from '../js/VueGlobal.js'
  import HomepageComponent from '../js/HomePage.js'

  createApp(MyComponent).mount('#app')
  createApp(HomepageComponent).mount('#homepage')

</script>

export in js page :

export default {
    data() {
      return { 
       
        }
    },
    // template will create html element in specified box which you have mounted in html page
    template: `
        <div>This is a test BOX</div>
   
  `
,
methods:{

       
}


}

fetch:

/*
template will be like below:

fetch(url,request).then()

request will include:
request method, request headers

after the 'then' method, you can handle your response here

Tip: you cannot monitor the stream process, so if you want to use a process bar , don't use fetch

*/

//This is a example for get data from backend 

fetch(url,{
            method: 'GET',        
           
            headers:{
            'Content-Type':'application/x.wwww-form-urlencoded',                                
            },
        }).then(res => res.json()).then(res=>{
        
            this.data = res
        })

//This is a example for post a form 

//first create a formData object
formData = new FormData()

//append data into formData obj
var inner_text = document.getElementsByName(name)[0].innerText
var inner_value = document.getElementsByName(name)[0].nextSibling.value
    
formdata.append(inner_text,inner_value)

//finally fetch the form
fetch(host+ ":8000"+ '/experience/create/',{
        method: 'POST',        
        body:formData,
        mode:'no-cors',
        headers:{
            'Content-Type':'application/x.wwww-form-urlencoded',                                
        },
      })

Detail for JS use (for someone don't use JS frequently)

// list | array operation

//add a element to list

list.push(el)

//remove a element from list 
//i for index, j for range

list.splice(i,j)

/*exapmle function:
list.map((val,i)=>{
            if(val===member){
               list.splice(i,1)                
            }
        })

*/

//use 'for' in JS
//item is the index of each member
//if you want to retrieve memebr, try list[item]
for(var item in list){
    
}

 

标签:Web,use,formData,启动,res,前端,list,js,fetch
From: https://www.cnblogs.com/lengblog/p/17097666.html

相关文章

  • 【Appium_python】启动app,出现多次打开关闭导致失败问题,driver用单例模式(_new_)进行解
    运用多设备,启动app多次出现打开又关闭问题,查看后是多次对driver进行实例化,就用单例的模式进行解决。单例模式(SingletonPattern)目的就是保证一个类仅有一个实例,每一次执行......
  • 前端总结-HTML篇
    HTML块级元素和行内元素块级元素:(div、p、table、ul-li、ol-li、h1—h6、form)默认宽度100%,在浏览器中占一行的位置padding、margin、width、height、border都设置有......
  • C#.NET 4.8 WEBP 转 GIF
    C#.NET4.8WEBP转GIF项目是.NET4.8。nuget引用 Magick.NET-Q16-AnyCPU,版本:7.14.5。高版本,如:12.2已经不支持.NETFRAMEWORK了。usingImageMagick;usingSyste......
  • 关于oushudb-hawq:OushuDB-基本用法-启动停止
    启动OushuDB有两种形式,一种是通过”hawqstartcluster”命令来启动整个集群,包含master和segment。启动哪些segment是由”/hawq-install-path/etc/slaves”中蕴含的节点确定......
  • 基于SpringBoot的WebSocket开发(非完整代码)
    1、添加依赖<!--websocket--><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starte......
  • 趣学前端 | 多个页面的操作聚合到某个页面的实现方案
    一、前言刚接到这个需求的时候我有点不想写,因为要把所有的页面全都改一遍,且要保证不出现问题,功能不难,但是工作量有点大。我小小的纠结了一下就着手去做了,因为我发现,一旦改好......
  • Backbone前端框架解读
    作者:京东零售陈震一、什么是Backbone在前端的发展道路中,前端框架元老之一jQuery对繁琐的DOM操作进行了封装,提供了链式调用、各类选择器,屏蔽了不同浏览器写法的差异性......
  • 8.5启动及库文件
    下图的错误消息表示的是无法解析Sample1.obj参照的外部符号。  外部符号是指其他目标文件中的变量或函数。sprintf及MessageBoxA是目标文件中sprintf及MessageBox()的......
  • 滴滴前端一面必会vue面试题(附答案)
    实现双向绑定我们还是以Vue为例,先来看看Vue中的双向绑定流程是什么的newVue()首先执行初始化,对data执行响应化处理,这个过程发生Observe中同时对模板执行编译,找到其中......
  • 前端vue面试题
    父子组件生命周期调用顺序(简单)渲染顺序:先父后子,完成顺序:先子后父更新顺序:父更新导致子更新,子更新完成后父销毁顺序:先父后子,完成顺序:先子后父diff算法时间复杂度:个树......