当前位置: 首页 > wzjs >正文

公司网页设计怎么弄宁波网站推广优化

公司网页设计怎么弄,宁波网站推广优化,wordpress 火车头发布规则,电脑网页加速器Vue实战2 通过create-vue创建Vue脚手架(npm为NodeJs的软件包管理器) Vue的创建 npm init vuelatest创建项目基本的选项 Vue项目的目录结构 启动Vue项目:npm run dev 或者通过npm脚本中的dev启动(vscode中的npm脚本打开方式通…

Vue实战2


通过create-vue创建Vue脚手架(npm为NodeJs的软件包管理器)

Vue的创建

npm init vue@latest创建项目基本的选项
在这里插入图片描述

Vue项目的目录结构

在这里插入图片描述

启动Vue项目:npm run dev

或者通过npm脚本中的dev启动(vscode中的npm脚本打开方式通过点击package.json文件就会出现)

Vue项目的入口文件是main.js
执行流程:
在这里插入图片描述

通过main.js的createApp方法将对应的App.vue导入

createApp(App).mount('#app')

在通过mount将此Vue实例关联到index.html中

<!DOCTYPE html>
<html lang=""><head><meta charset="UTF-8"><link rel="icon" href="/favicon.ico"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>Vite App</title></head><body><div id="app"></div><script type="module" src="/src/main.js"></script></body>
</html>

App.vue分为三个部分

template:编写HTML代码

style:编写CSS代码

script:编写JS代码

<!-- <script>
// 写数据
// 默认导出---》用于填充在main.js中的createApp()方法中
export default {data() {return {msg: "上海"};}
};
</script> -->
<script setup>import { ref } from "vue";const msg = ref("西安");//ref 创建响应式数据
</script>
<template><!-- HTML代码 --><!-- <h1>北京</h1> --><h1>{{ msg }}</h1>
</template><style scoped>
/* CSS代码 */
h1 {color: red;
}
</style>


Vue的API风格(组合式API和选项式API)

在这里插入图片描述

组合式API必须通过.value才能获取或者修改数据

Api.vue:

<script setup>import { ref,onMounted } from 'vue'// 声明响应式数据 ref,响应式的对象内部有一个属性 value// 在组合式API中一般需要将数据定义为响应式数据const count = ref(0);// 声明函数const increment = () => {count.value++;}// 声明钩子函数onMounted(() => {console.log('组件挂载完毕');})
</script><template><!-- 写HTML元素 --><button @click="increment">count:{{ count }}</button>
</template>

导入Api.vue到App.vue中:通过默认导入取的别名进行调用对应的子组件的内容

<ApiVue></ApiVue>或者<ApiVue/>

import ApiVue from "./Api.vue";
<script setup>import { ref } from "vue";const msg = ref("西安");//ref 创建响应式数据// 导入Api.vue组件import ApiVue from "./Api.vue";
</script>
<template><!-- HTML代码 --><!-- <h1>北京</h1> --><h1>{{ msg }}</h1><ApiVue></ApiVue>
</template><style scoped>
/* CSS代码 */
h1 {color: red;
}
</style>

综合案列:axios.get('http://localhost:8080/article/search',{params:{...searchCondition.value}})表示通过axios进行异步请求同时通过params进行参数的传递(...searchCondition.value表示解析这个响应式对象中的数据)

工程化的使用axios的时候通过npm install axios先导入库文件

import axios from 'axios'
<script setup>
// 通过钩子函数获取所有的文章数据
import { onMounted, ref } from 'vue'
// 引入axios  npm install axios
// axios 为默认导出的 因此需要直接进行默认导入
import axios from 'axios'// 声明响应式数据
const articleList = ref([])// 发送异步请求获取文章数据
axios.get('http://127.0.0.1:8080/article/getAll')
.then(result => {// 把服务器响应的数据保存起来articleList.value = result.data
}).catch(err => {console.log(err)
});// 指定响应式数据通过v-model进行双向绑定
const searchCondition=ref({category:'',state:''
})// 为搜索按钮绑定点击事件
// function search(){
//     axios.get('http://127.0.0.1:8080/article/search?category='+searchCondition.value.category+'&state='+searchCondition.value.state)
//     .then(result => {
//         // 把服务器响应的数据保存起来
//         articleList.value = result.data
//     }).catch(err => {
//         console.log(err)
//     });
// }
const search = () => {axios.get('http://127.0.0.1:8080/article/search?category='+searchCondition.value.category+'&state='+searchCondition.value.state)// axios.get('http://localhost:8080/article/search',{params:{...searchCondition.value}}).then(result => {// 把服务器响应的数据保存起来articleList.value = result.data}).catch(err => {console.log(err)});
}
</script><template><div>文章分类: <input type="text" v-model="searchCondition.category">发布状态: <input type="text" v-model="searchCondition.state"><button @click="search">搜索</button><br /><br /><table border="1 solid" colspa="0" cellspacing="0"><tr><th>文章标题</th><th>分类</th><th>发表时间</th><th>状态</th><th>操作</th></tr><tr v-for="article in articleList"><td>{{article.title}}</td><td>{{article.category}}</td><td>{{article.time}}</td><td>{{article.state}}</td><td><button>编辑</button><button>删除</button></td></tr></table></div></template>

将对应的文章服务方法放在另外一个js文件中通过导出的形式在这个Vue中进行调用

// 导入axios
import axios from 'axios'// 定义一个变量,用于记录公共的前缀,BaseUrl
const BaseUrl = 'http://127.0.0.1:8080'
const instance = axios.create({baseURL: BaseUrl
})// 获取所有文章数据的函数
// 由于是axios的异步操作,所以不能同步获取到对应的响应的结果
// 需要同步等待服务器响应的结果并进行返回等待的结果---》
// async设定为异步  await:等待同步返回的结果(只能用在 async 异步函数中)
export async function articleGetAllService(){return await instance.get('/article/getAll').then(result => {// 把服务器响应的数据直接进行返回return result.data}).catch(err => {console.log(err)});
}// 根据文章的分类和发布状态搜索的函数
export async function articleSearchService(conditions){return await instance.get('/article/search',{params:conditions}).then(result => {// 把服务器响应的数据直接进行返回return result.data}).catch(err => {console.log(err)});
}

引入文章相关的服务函数@/表示的是src目录

<script setup>
// 通过钩子函数获取所有的文章数据
import { onMounted, ref } from 'vue'
// 引入axios  npm install axios
// axios 为默认导出的 因此需要直接进行默认导入
import axios from 'axios'
// 引入文章相关的服务函数@/表示的是src目录
import { articleGetAllService,articleSearchService } from '@/api/article'// 声明响应式数据
const articleList = ref([])// 发送异步请求获取文章数据
// 同步获取articleGetAllService函数的返回值
const getAllArticle =async function() {let data=await articleGetAllService()articleList.value=data
}
getAllArticle();// 指定响应式数据通过v-model进行双向绑定
const searchCondition=ref({category:'',state:''
})
// 为搜索按钮绑定点击事件
const search =async function() {let data=await articleSearchService({...searchCondition.value})articleList.value=data
}</script>

async设定为异步,await等待异步操作返回结果

通过如下代码可以设定指定的请求路径的前缀

// 导入axios
import axios from 'axios'// 定义一个变量,用于记录公共的前缀,BaseUrl
const BaseUrl = 'http://127.0.0.1:8080'
const instance = axios.create({baseURL: BaseUrl
})

通过一个对于异步请求axios设定一个响应的拦截器,再将axios的实例进行导出,在另一个js文件中导入就不需要处理对应的then,catch操作了

在这里插入图片描述

// 定制请求的实例
// 导入axios
import axios from 'axios'// 定义一个变量,用于记录公共的前缀,BaseUrl
const BaseUrl = 'http://127.0.0.1:8080'
const instance = axios.create({baseURL: BaseUrl
})// 添加响应的拦截器
instance.interceptors.response.use(// function (response) {//     // 对响应数据做点什么//     return response.data// },result=>{return result.data},// function (error) {//     // 对响应错误做点什么//     alert('服务器出错了')//     return Promise.reject(error)//将异步的状态转化为失败的状态// }err=>{alert('服务器出错了')return Promise.reject(err)}
)export default instance
import request from '@/util/request.js'
export function articleGetAllService(){return request.get('/article/getAll')
}// 根据文章的分类和发布状态搜索的函数
export function articleSearchService(conditions){return request.get('/article/search',{params:conditions})
}
http://www.dtcms.com/wzjs/835924.html

相关文章:

  • 怎么建网站新手入门软件开发成本估算
  • 青岛网站seo技巧网站设计风格介绍
  • 做网站教程 简书亚马逊插件WordPress
  • 销售珍珠网站建设策划书网站优化分析
  • 安徽海川建设公司网站注册网站租空间哪里租
  • 企业网站设计制作教程wordpress全站静态
  • 网站布局f网站建设脑图
  • 企业营销微网站建设没有网站 可以做cpa
  • 自己怎么做卖东西的网站东莞网络优化
  • 响应式网站 翻译代码wordpress 未加密
  • 最超值的锦州网站建设济南网站优化公司电话
  • 表白时刻网站上海外贸公司地址
  • 瑞安规划建设局网站陕西网站建设
  • 马云有没有学过做网站WordPress担保系统
  • 济南企业网站设计公司wordpress更改首页
  • 重庆营销型网站随做的好处wordpress轮播图源码
  • 设计商标的网站加工平台调平装置
  • 俱乐部网站模板哪个网站可以领单做效果图
  • 建设一个网站大概多少钱网站建设编程时注意事项
  • 免费建站免费网站海文考研培训班2023价格表
  • 浙江省网站集约化建设通知上海公共招聘网下载
  • 哪些门户网站可以做推广网站建设静态部分实训总结
  • 邯郸有学做搭建网站的吗如何注册公司微信公众号
  • 网站建设中英语深圳官网建站服务商
  • 网站发布之后上传文件路径变了迅雷下载宝 做网站
  • 网站模板下载之后怎么做什么播放器能看无线新闻台直播
  • 青海省住房和城乡建设厅 网站天河网站建设
  • 网站设计就业岗位分析门户网站开发需求文档
  • 网站文章结构变更怎么做301茂名营销型网站制作公司
  • 做带会员后台的网站用什么软件长沙短视频公司