小编Yom*_* S.的帖子

VueJS:同时使用 v-model 和 :value

我正在寻找一种在同一对象上同时使用v-model和 的方法。:value

我收到这个错误:

:value="user.firstName"v-model与同一元素冲突,因为后者已经在内部扩展为值绑定。

目的是将从(来自一个商店)获取的值设置为默认值mapGetters,并在用户提交修改时设置正确的值。(在onSubmit

<div class="form-group m-form__group row">
    <label for="example-text-input" class="col-2 col-form-label">
        {{ $t("firstname") }}
    </label>
    <div class="col-7">
        <input class="form-control m-input" type="text" v-model="firstname" :value="user.firstName">
    </div>
</div>


<script>
import { mapGetters, mapActions } from 'vuex';

export default {
    data () {
        return {
            lang: "",
            firstname: ""
        }
    },
    computed: mapGetters([
        'user'
    ]),
    methods: {
        ...mapActions([
            'updateUserProfile'
        ]),
        onChangeLanguage () {
            this.$i18n.locale = lang;
        },
        // Function called when user click …
Run Code Online (Sandbox Code Playgroud)

vue.js vuejs2 v-model

6
推荐指数
1
解决办法
2万
查看次数

使用 VUE CLI 3.x 时如何向加载器添加新规则

在过去的几天里,我尝试在 Vue-router 中引用 HTML 页面,但无论我尝试了什么,我得到的唯一结果是以下错误:

模块解析失败:意外的标记 (1:0) 您可能需要适当的加载程序来处理此文件类型,当前没有配置加载程序来处理此文件。

我已经尝试了许多不同的堆栈响应来修复它,但其中大多数实际上需要在webpack.config.js.

{
  test: /\.(html)$/,
  use: {
    loader: "html-loader",
    options: {
      attrs: [":data-src"]
}
Run Code Online (Sandbox Code Playgroud)

然而,在最新版本的 Vue CLI 中,该文件似乎不再可用。

HTML 页面放置在public/static目录中,因此当我从 访问它时它运行良好 localhost:8080/static/home.html,但我的目标是将其作为我的主页访问(localhost:8080/ 仅使用)。

到目前为止,我已经安装了两者html-loadervue-loader但还没有成功的迹象。

PS 我曾尝试将此 HTML 文件及其补充文件(css、字体和 js)转换为组件,但也没有成功。

html webpack vue.js

6
推荐指数
1
解决办法
8104
查看次数

在 v-select 中更改芯片的样式和颜色

如何更改芯片的颜色和样式v-select

我有这样的代码:

<v-select
  v-model="value"
  :items="roles"
  :menu-props="{ top: true, offsetY: true }"
  small-chips
  label="Roles"
  multiple
  hint="Select the role"
  persistent-hint
>
</v-select>
Run Code Online (Sandbox Code Playgroud)

在此处输入图片说明

如何将筹码更改为样式标签蓝色

vue.js vuejs2 vuetify.js v-select

6
推荐指数
1
解决办法
4907
查看次数

VueJS,ReferenceError:未定义谷歌

我有以下源代码,当我尝试使用以下命令实例化一个新 var 时,我也遇到了以下错误google.maps ...

谷歌'未定义

许多答案都谈到在其他所有事情之前异步加载 API 脚本,并且脚本的顺序很重要,但我认为这不是我的问题。

PS:我用这个 main.js

Vue.use(VueGoogleMaps, {    
  load: {    
    key: 'MY-KEY',    
    libraries: 'places', //// If you need to use place input    
  },    
})     
Run Code Online (Sandbox Code Playgroud)

谁能帮我?谢谢。

<div class="map-container">     
       <gmap-map     
         id="map"     
         ref="map"     
         :center="center"     
         :zoom="15"     
         map-type-id="roadmap"     
         style="width:100%;  height: 400px;">     
           <gmap-marker     
           :key="index"    
            v-for="(m, index) in markers"    
            :position="m.position"    
             @click="center=m.position"    
             ></gmap-marker>    
                </gmap-map>
            </div>
Run Code Online (Sandbox Code Playgroud)
<script>    
    import _ from 'lodash'    
    import { mapState } from 'vuex'    
    import * as VueGoogleMaps from 'vue2-google-maps'   

    export default {    
      computed: {    
        ...mapState([    
          'map',    
        ]),    
        mapStyle: function …
Run Code Online (Sandbox Code Playgroud)

javascript google-maps vue.js vuejs2 vue2-google-maps

3
推荐指数
1
解决办法
1万
查看次数

Vue Composition API:有没有更好的方法在可消费文件中调用`emit`?

emit在分离的逻辑文件中访问的正确方法(或更好的方法)是什么?

这就是我目前所做的工作:

foo.js

export default (emit) => {
    const foo = () => { emit('bar') };
    return { foo };
}
Run Code Online (Sandbox Code Playgroud)

然后在消费组件上:

import { defineComponent } from '@vue/composition-api';
import foo from './foo';

export default defineComponent({
  setup(props, { emit }) {
    const { foo } = foo(emit);
    return { foo };
  }
});
Run Code Online (Sandbox Code Playgroud)

但我想知道是否有更合适的方法来做到这一点?或者emit在可消耗文件中调用是一种不好的做法吗?

javascript typescript vue.js vuejs3 vue-composition-api

3
推荐指数
1
解决办法
3905
查看次数

Vue3 与强类型 Axios 请求

我正在尝试了解 Vue3、TypeScript 和 Axios 的一些“类型安全”基础知识。

这是非常简单的东西,我觉得我好像错过了一些明显的东西!

我创建了一个Book界面:

图书.ts

interface Book {
  id: string;
  userId: string;
  title: string;
  content: string;
}

export default Book;
Run Code Online (Sandbox Code Playgroud)

我还创建了一个简单的服务来获取一些 JSON,例如

  {
    "userId": 1,
    "id": 1,
    "title": "sunt aut facere repellat provident occaecati excepturi optio reprehenderit",
    "body": "quia et suscipit\nsuscipit recusandae consequuntur expedita et cum\nreprehenderit molestiae ut ut quas totam\nnostrum rerum est autem sunt rem eveniet architecto"
  },
Run Code Online (Sandbox Code Playgroud)

(注:JSON有body而不是content接口上定义的)

数据服务.ts

import axios, { AxiosResponse } from "axios";
import Book from …
Run Code Online (Sandbox Code Playgroud)

typescript vue.js axios vuejs3

2
推荐指数
1
解决办法
2970
查看次数