Vue3 css实现背景图片

style中background-image属性决定图片 

<style>
.logincontent {
  display: flex;
  flex-direction: column;
  background-image: url("/src/assets/background.png");
  background-size: 100% 100%;
  background-attachment: fixed;

  width: 100%;
  height: 100%;
  min-width: 900px;
  min-height: 1000px;

  justify-content: center;
  align-items: center;
}
.loginform {
  background-color: #fff;
  min-width: 600px;
  box-shadow: rgba(0, 0, 0, 0.1) 0px 15px 30px;
  padding: 30px 20px;
}
</style>

实现源码 (注意两个class)

<template>
  <a-layout class="logincontent">
    <a-form
      class="loginform"
      :model="user"
      :label-col="labelCol"
      :wrapper-col="wrapperCol"
    >
      <a-typography-title style="text-align: center"
        >用户登录</a-typography-title
      >
      <a-form-item label="公钥" :wrapper-col="{ span: 15, offset: 4 }">
        <a-input v-model:value="user.public_key" placeholder="请输入公钥" />
      </a-form-item>
      <a-form-item label="私钥" :wrapper-col="{ span: 15, offset: 4 }">
        <a-input-password
          v-model:value="user.private_key"
          placeholder="请输入私钥"
        />
      </a-form-item>
      <a-form-item :wrapper-col="{ span: 12, offset: 6 }">
        <a-row type="flex" justify="space-between">
          <a-button type="primary" @click="login">登录</a-button>
          <a-button type="link" @click="goToRegister"
            >没有账号?立即注册</a-button
          >
        </a-row>
      </a-form-item>
    </a-form>
  </a-layout>
</template>
<script setup>
import { reactive } from "vue";
import { post, setLocalToken, tip } from "@/common";
import { useRouter } from "vue-router";

const router = useRouter();

//reactive 双向绑定响应框
const user = reactive({
  public_key: "",
  private_key: "",
});

const goToRegister = () => {
  router.push({ path: "/register" });
};

const login = () => {
  console.log("登录!");
  post("/security/login", user).then((res) => {
    tip.success("登陆成功!");
    const token = res.data; //获取返回的令牌
    // 将令牌存储在本地
    setLocalToken(token);

    // 跳转至Home路由
    router.push({ path: "/home" });
  });
};
</script>
<style>
.logincontent {
  display: flex;
  flex-direction: column;
  background-image: url("/src/assets/background.png");
  background-size: 100% 100%;
  background-attachment: fixed;

  width: 100%;
  height: 100%;
  min-width: 900px;
  min-height: 1000px;

  justify-content: center;
  align-items: center;
}
.loginform {
  background-color: #fff;
  min-width: 600px;
  box-shadow: rgba(0, 0, 0, 0.1) 0px 15px 30px;
  padding: 30px 20px;
}
</style>

效果图

  • 4
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Vue中,要实现背景图片铺满整个页面的效果,可以通过在App.vue文件中设置style的方式来实现。你可以在style标签中添加如下的CSS代码来达到目的: ```css <style> body { margin: 0; padding: 0; background-image: url('your_image_url'); background-size: cover; background-position: center; background-repeat: no-repeat; } </style> ``` 在这段代码中,我们给body元素设置了0的外边距和内边距,然后将背景图片的URL设置为你想要的图片路径。通过`background-size: cover;`,背景图片会被缩放到适应整个页面,而且保持其宽高比例。`background-position: center;`将背景图片在页面上居中显示,`background-repeat: no-repeat;`则表示不重复平铺背景图片。 这样设置之后,背景图片就会铺满整个页面了。如果你希望当内容增多,高度超过屏幕高度时背景图片仍然能够完全铺满,可以使用第一种方式进行设置。但需要注意的是,在Vue中,你需要将这段CSS代码添加到App.vue文件的style标签中。 希望这个解答对你有所帮助!<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* [VUE解决背景图片没有铺满的问题](https://blog.csdn.net/bbs11007/article/details/123980171)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 33.333333333333336%"] - *2* [vue组件中设置背景图片,随着页面高度的增加,背景图片能够不断延伸铺满屏幕](https://blog.csdn.net/scarlett1017/article/details/123541811)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 33.333333333333336%"] - *3* [CSS实现网页背景图片自适应全屏的方法](https://download.csdn.net/download/weixin_38689055/13607972)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 33.333333333333336%"] [ .reference_list ]

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值