代码之家  ›  专栏  ›  技术社区  ›  psudo

Vue JS中的对象HtmlTextAreaElement

  •  0
  • psudo  · 技术社区  · 6 年前

    我在用 "laracasts/utilities" Laravel包将Laravel变量传递到JS文件。以下是我在控制器中的代码:

            JavaScript::put([
            'description' => $room->description
        ]);
    

    我的Vue JS代码:

    var keywordcount = new Vue({
    el: "#desc-edit",
    data: {
        maxdesc: 160,
        desc: description
    },
    computed: {
        descEdit: function() {
            return this.maxdesc - this.desc.length;
        }
     }
    });
    

    我得到输出 [object HTMLTextAreaElement] 在我的编辑窗体的文本区域中。我试过了 desc: window.description 作为 'js_namespace' => 'window' 在配置文件中列出。

    如何以纯文本形式获取输出?

    1 回复  |  直到 6 年前
        1
  •  1
  •   Jacob Goh    6 年前

    [object HTMLTextAreaElement] 是textArea dom元素(转换为字符串)。要获取其文本值,可以添加 .value 到元素。

    例如,如果 window.description 是textArea元素,然后 window.description.value 提供文本值。所以你想要的可能是,

    data: {
        // ...
        desc: window.description.value
    },