Vue项目工程化创建和启动

一.Vue项目创建和启动

1.创建一个工程化的Vue项目

在这里插入图片描述

执行命令:npm init vue@latest

2.Vue项目安装依赖

在这里插入图片描述

执行命令:npm install

外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传


3.vue项目—目录结构

外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传


4.启动项目

外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传

1.执行命令:npm run dev

外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传

2.通过VS code NPM脚本启动


二、Vue项目开发流程

外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传

App.vue:

外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传

外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传


三.Api风格

组合式api

选项式api

外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传

组合式Api

外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传

外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传

前端工程化案例代码:

<script setup>
    //导入axios npm install axios
    import axios from 'axios';
    import {ref} from 'vue'
    //定义响应式数据 ref
    const articleList = ref([]);
​    //发送异步请求,获取所有文章数据
​    axios.get('http://localhost:8080/article/getAll')
​    .then(result=>{
​      //把服务器相应的数据保存起来
​      articleList.value = result.data;}).catch(err=>{
​      console.log(err)})
        //定义响应式数据 searchConditions
​    const searchConditions = ref({
​        category:'',
​        state:''})
​    //声明search函数
​    const search = function(){
​        //发送请求,完成搜索
​        axios.get('http://localhost:8080/article/search',{params:{...searchConditions.value}})
​        .then(result=>{articleList.value=result.data
​        })
​        .catch(err=>{
​            console.log(err)})}
</script>

<template>
  <div>
            文章分类:<input type="text" v-model="searchConditions.category"/>
            发布状态:<input type="text" v-model="searchConditions.state"/>
            <button @click="search">搜索</button>
            <button v-on:click="clear">重置</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="(item,index) in articleList" :key="index">
                    <td>{{item.title}}</td>
                    <td>{{item.category}}</td>
                    <td>{{item.time}}</td>
                    <td>{{item.state}}</td>
                    <td>
                        <button>编辑</button>
                        <button>删除</button>
                    </td>
                </tr>
            </table>
  </div>
</template>
<style >
</style>
  • 24
    点赞
  • 12
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值