首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何使用vue3 dayjs

如何使用vue3 dayjs
EN

Stack Overflow用户
提问于 2022-09-28 05:50:18
回答 1查看 33关注 0票数 1

尝试用vue3做dayjs时,当我不使用dayjs时,效果很好。当我输入该代码时,我会收到一个错误,说明“date_posted”不能被访问,并且没有显示在屏幕上。我缺少了一个vue3设置吗?白天有什么特别的环境吗?dayjs的使用只搜索vue2,却找不到vue3。

代码语言:javascript
运行
复制
<template>
  <div class="container">
    <Sidebar />
    <div class="notice_write">
      <div class="wright_wrap">
        <h3 class="box_title">
          Notice write
        </h3>
        <form
          class="form_box"
          @submit.prevent="formCreate()">
          <div class="in_title">
            <h3 class="sub_title">
              title
            </h3>
            <textarea
              v-model="form.title"
              maxlength="100"></textarea>
          </div>
          <div class="in_title">
            <h3 class="sub_title">
              company
            </h3>
            <textarea
              v-model="form.company"
              maxlength="100"></textarea>
          </div>
          <div class="in_title">
            <h3 class="sub_title">
              company url
            </h3>
            <textarea
              v-model="form.company_url"
              maxlength="100"></textarea>
          </div>
          <div class="in_title">
            <h3 class="sub_title">
              location
            </h3>
            <textarea
              v-model="form.location"
              maxlength="100"></textarea>
          </div>
          <div class="in_title">
            <h3 class="sub_title">
              days
            </h3>
             //This Problem code
            <p>{{ form.date_posted }}</p>
          </div>
          <div class="in_title contents">
            <h3 class="sub_title">
              content
            </h3>
            <textarea v-model="form.description"></textarea>
          </div>
          <div class="button_wrap">
            <button
              type="reset"
              class="writing_btn cancle_btn">
              cancle
            </button>
            <button
              class="writing_btn writing_done">
              Add write
            </button>
          </div>
        </form>
      </div>
    </div>
  </div>
</template>
<script setup>
import Sidebar from '~/components/Sidebar.vue'
import { ref } from 'vue'
import { useRouter } from 'vue-router'
import dayjs from 'dayjs'
import axios from 'axios'

const router = useRouter()

const form = ref({
  title: null, 
  company: null, 
  company_url: null, 
  location: null, 
  description: null,
  date_posted: Date.now()
})
//This Problem code
const date_posted = dayjs(date_posted).format('YYYY-MM-DD-HH-mm-ss초')
const formCreate = async (id) => {
    let token = sessionStorage.getItem('access_token')
    const data = {
        title: form.value.title,
        company: form.value.company,
        company_url: form.value.company_url,
        location: form.value.location,
        description: form.value.description,
        date_posted: form.value.date_posted,
      }
    console.log(form)
  try {
    await axios.post('http://127.0.0.1:8000/jobs/create-job/', data, {
      headers: {
        'Content-Type': 'application/json' ,
         'Authorization' : token
        }, 
      withCredentials:true,
      params:{
        id
      }
    })
    .then((res)=>{
    console.log(res.data)
    })
  } catch (error) {
    console.log(error)
  }
}
 </script>
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2022-09-28 06:04:23

它与day.js无关,这是因为在初始化之前使用了date_posted const

代码语言:javascript
运行
复制
const date_posted = dayjs(date_posted).format('YYYY-MM-DD-HH-mm-ss초')

但是您需要从表单ref获得它,所以它应该如下所示。

代码语言:javascript
运行
复制
const date_posted = dayjs(form.value.date_posted).format('YYYY-MM-DD-HH-mm-ss초')
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/73876708

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档