小编Bou*_*him的帖子

在 Vue.js 3 中,为什么我必须在 ref 上使用 value 属性,而不是在 React 上使用?

基本上,标题已经说明了一切:In Vue.js 3, Why do I have to use the valueproperty on ref, but not onreactive

\n

我知道这ref是针对简单值,例如布尔值、数字、\xe2\x80\xa6,并且reactive针对复杂值,例如对象和数组。我不明白的是:

\n
    \n
  • 为什么我需要指定value何时访问 aref的值,但如果使用 则不需要指定reactive这不是 API 中的不一致吗?或者是否存在实际的技术原因?
  • \n
  • 为什么我不能同时使用其中之一?换句话说:是否有技术原因导致没有一个函数根据给定值的类型决定如何在内部包装它?
  • \n
\n

我认为我错过了一些东西,但事实并非如此。有人可以帮忙吗?

\n

javascript vue.js vuejs3 vue-composition-api

5
推荐指数
1
解决办法
3105
查看次数

Ant Design Vue:当只有一个 div 内容时,轮播箭头消失

我正在使用 Ant Design Vue 的 Carousel 在 Instagram Story Clone 项目中显示一些后端生成的数据。

问题是当轮播中只有一个内容时,箭头和圆点就会消失。

轮播文档:https : //antdv.com/components/carousel

代码沙盒:https : //codesandbox.io/s/brave-blackwell-e6d5c? file =/ src/ App.vue

箭头显示:

<a-carousel arrows>

    <!-- Left Arrow -->
    <div
      slot="prevArrow"
      slot-scope="props"
      class="custom-slick-arrow"
      style="left: 10px;zIndex: 1"
    >
      <a-icon type="left-circle" />
    </div>

    <!-- Right Arrow -->
    <div
      slot="nextArrow" 
      slot-scope="props"
      class="custom-slick-arrow" 
      style="right: 10px"
    >
      <a-icon type="right-circle" />
    </div>

    <div><h3> Content 1 </h3></div>
    <div><h3> Content 2 </h3></div>
  </a-carousel>
Run Code Online (Sandbox Code Playgroud)

箭头不显示:

<a-carousel arrows>

    <!-- Left Arrow -->
    <div
      slot="prevArrow"
      slot-scope="props"
      class="custom-slick-arrow"
      style="left: 10px;zIndex: …
Run Code Online (Sandbox Code Playgroud)

javascript css vue.js vue-component antdv

5
推荐指数
1
解决办法
440
查看次数

Vue CLI 4.5.*:“在‘vue’中找不到导出‘默认’(导入为‘Vue’)

在使用 Vue CLI 4.5.x 时,我尝试了以下代码:

import Vue from "vue"
import App from './App.vue'

new Vue({
    el: "#app",
    render: h=> h(App)
})
Run Code Online (Sandbox Code Playgroud)

但不幸的是,它给出了以下警告:

"export 'default' (imported as 'Vue') was not found in 'vue'

我可以从中得出的结论是,Vue CLI 4.5.x 已经停止了这种首先创建 Vue 实例的应用程序创建方式。

初始化主应用程序,官方的方式如下:

import { createApp } from 'vue'
import App from './App.vue'

createApp(App).mount('#app')
Run Code Online (Sandbox Code Playgroud)

我不确定我的结论是否正确。如果有人能具体说明我的结论,那将是一个很大的帮助,因为到目前为止我还没有在 vue 的官方文档中找到任何证据。

此外,后面的代码是使用 Vue CLI 4.5.* 应用程序实例烘焙的,而前面的代码在使用 CDN 时是正确的。

vue.js vue-component vuejs2 vuejs3 vue-cli-4

5
推荐指数
1
解决办法
7428
查看次数

使用 Typescript 注入 Vue 3

我使用了新的 Vue 3 Composition API 并为响应式数据编写了一个“存储”。

const state = reactive<State>({
  accessToken: undefined,
  user: undefined,
});

export default {
  state: readonly(state),
}
Run Code Online (Sandbox Code Playgroud)

在创建应用程序时,我向所有组件提供商店:

const app = createApp(App)
  .provide("store", store)
  .use(IonicVue)
  .use(router);
Run Code Online (Sandbox Code Playgroud)

最后在一个组件/视图中,我注入了 store 来使用它。

export default defineComponent({
  name: "Home",
  inject: ["store"],
  components: {
    IonContent,
    IonHeader,
    IonPage,
    IonTitle,
    IonToolbar,
    IonButton,
  },
  computed: {
    email() {
      return this.store.state.user.email;
    },
  },
});
</script>
Run Code Online (Sandbox Code Playgroud)

不幸的是,Typescript 不喜欢this.store计算属性中使用的方式email()

并说

类型“ComponentPublicInstance<{}、{}、{}、{ email(): any;”上不存在属性“store”;}, {}, EmitsOptions, {}, {}, false, ComponentOptionsBase<{}, {}, {}, …

typescript vue.js vuejs3

5
推荐指数
2
解决办法
1817
查看次数

如何使用 Vue3 和 Typescript 在 Quasar Framework 中定义 ref 方法的类型

  • Quasar 框架 v2 测试版
  • Vue 3 组合 API
  • 打字稿

组件模板

<q-btn 
  @click.stop="showingActionMenu()" 
  color="grey-7" 
  round 
  flat 
  icon="more_vert"
>
  <q-menu
    ref="showAction"
    auto-close
  >
    ...                       
  </q-menu>
</q-btn>
Run Code Online (Sandbox Code Playgroud)
setup() {
  ...
  const showAction = ref<Function | null>(null)
  ...
})
Run Code Online (Sandbox Code Playgroud)

组件设置

return {
  ...
  showAction,
  showingActionMenu() {
    showAction?.value?.show()
  },
  ...
}
Run Code Online (Sandbox Code Playgroud)

返回的方法显示错误

Property 'show' does not exist on type 'Function'.
Run Code Online (Sandbox Code Playgroud)

typescript vue.js quasar-framework vue-composition-api

5
推荐指数
1
解决办法
3798
查看次数

如何在 VueCli 中不使用文件名散列进行构建

我想构建我的应用程序并导出没有随机数的文件,例如app.e48201ef.jsapp.js。

我的应用程序位于 Wordpress 根目录的 /app/ 文件夹中,我将 js 文件一个一个地包含在模板中,以对 .

问题是我真的对 webpack、vue.config.js 感到困惑,事实上 Webpack 现在包含在 VueCLi3 中,我将文件包含在 index.html 中,我不使用它。

如何为每个文件设置静态名称以保持我的应用程序在生产中更新?

谢谢你。

vue.js vue-cli-3

4
推荐指数
1
解决办法
3129
查看次数

v-html 中的 Vue.js v-model

我想将 html 存储在变量内。例子:

\n\n
data: function() {\n  return {\n    my_html: \'<input type="text" v-model="data"\'\n  }\n}\n
Run Code Online (Sandbox Code Playgroud)\n\n

我想在数据中接收用户在字段中输入的值。但此连接不起作用\n完整示例:

\n\n
var test = new Vue({\n  el: \'#some_id\',\n  data: function() {\n    return {\n      data: \'\',\n      my_html: \'<input type="text" v-model="data" />\'\n    }\n  },\n  template: \n    \'<div>\n      <input type="text" v-model="data" />\n      <input type="text" v-model="data" />\n      <span v-html="my_html"></span>\n    </div>\'\n});\n
Run Code Online (Sandbox Code Playgroud)\n\n

在此示例中,前两个输入通常会与数据链接并相互链接,但第三个输入(跨度内的输入)将\xe2\x80\x99t

\n

html javascript vue.js vue-component vuejs2

4
推荐指数
1
解决办法
8606
查看次数

如何为子组件中的图像绑定 :src ?

我正在尝试呈现组件列表。除了 img src url 之外,所有数据属性都正确显示。

文件/文件夹是:

CryptContent.vue - 包含 v-for

  • 渲染资产的组件/ - 包含图像

CryptContent.vue 包含:

<template>
<OwnedCardContent
            v-for="card in allCards"
            :id="card.id"
            :name="card.name"
            :cost="card.cost"
            :cset="card.cset"
            :edition_total="card.edition_total"
            :level="card.card_level"
            :unlock_czxp="card.unlock_czxp"
            :buy_czxp="card.buy_czxp"
            :transfer_czxp="card.transfer_czxp"
            :sacrifice_czxp="card.sacrifice_czxp"
            :url="card.graphic"
            :card_class="card.bg"
></OwnedCardContent>
</template>

<script>
allcards : [
      {id:0, name: 'Jim Zombie',graphic: './assets/jim.svg', cost: 300, cset: 'We like to party set', edition_total: ' of 100',unlock_czxp : '1,300,300',card_level: 80, buy_czxp: '1,800',transfer_czxp: '100', sacrifice_czxp: '2,300',bg: 'card-bg card-bg-6'},
]
 </script>`
Run Code Online (Sandbox Code Playgroud)

OwnedCardContent.vue 包含:

<template>
<div id="1" :class="card_class">
            <img class="card-img" :src="url" />
            <span class="card-edition">#1{{edition_total}}</span>
            <div …
Run Code Online (Sandbox Code Playgroud)

html javascript vue.js vue-component vuejs2

4
推荐指数
1
解决办法
1046
查看次数

无法在 vuetify 对话框的字符串中插入新行

我试图通过在字符串中使用 \n 在作为 Vuetify 对话框文本的字符串中插入一个新行。但它不起作用。

这是调用 Vuetify 对话框的函数的代码

handleDialog()
{
    this.dialogHeading = "Clearing all component data"
    this.dialogText = "Do you really want to clear all the component data?\nThis will clear the components except the pressure and composition basis!"
    this.dialogBtn1 = "Cancel"
    this.dialogBtn2 = "Yes"
    this.isDialog = true
  
}
Run Code Online (Sandbox Code Playgroud)

这是显示 Vuetify 对话框的代码

<v-layout row wrap  >
   <v-flex class="text-xs-center">
       <v-dialog v-model="isDialog" persistent max-width=400>
          <v-card>
              <v-card-title  class=" error title white--text 
              darken-2 font-weight-bold">{{dialogHeading}}
              </v-card- title>
              <v-card-text>{{dialogText}}</v-card-text>
              <v-card-text v-if="dialogText2">{{dialogText2}}
              </v-card-text>

              <v-card-actions   >
                <v-btn  v-if="dialogBtn1" flat …
Run Code Online (Sandbox Code Playgroud)

javascript vue.js vue-component vuejs2 vuetify.js

4
推荐指数
2
解决办法
9360
查看次数

在Vue3中使用过滤器但无法读取globalProperties

只是一个简单的问题,

我知道 Vue3 不再使用过滤器,并且注释说使用计算或方法代替。但还有一个我们可以使用的 globalProperties,我使用了这个 globalProperties 但不断收到此错误

未捕获的类型错误:无法读取未定义的属性“globalProperties”

有谁知道我的代码中的错误在哪里?

const app = {
data() {
    return {
        message: ""
    }
  }
}

app.config.globalProperties.$filters = {
formatDate(value) {

    if (value == "0001-01-01T00:00:00")
        return "";
    var today = new Date(value);
    var dd = String(today.getDate()).padStart(2, '0');
    var mm = String(today.getMonth() + 1).padStart(2, '0'); //January is 0!
    var yyyy = today.getFullYear();

    today = dd + '/' + mm + '/' + yyyy;
    return today;
   }
}

Vue.createApp(app).mount('#app');
Run Code Online (Sandbox Code Playgroud)

我在表中使用过滤器,如下所示

    <td>
         {{ $filters.formatDate(incident.incidentData) }}
    </td>
Run Code Online (Sandbox Code Playgroud)

vue.js vuejs3

4
推荐指数
1
解决办法
4767
查看次数