小编Art*_*ira的帖子

如何在DOM事件调用的方法中更改Vue.js数据值?

免责声明:我知道Vue.js中有数据.

所以我有这个:

<html>
<body>

    <div id="app">
        <input @input="update">
    </div>

    <script src="https://unpkg.com/vue@2.1.10/dist/vue.js"></script>
    <script type="text/javascript">

        new Vue({

            el: '#app',

            data: {

                info: '',

            },

            methods: {

                update: function (event) {

                    value = event.target.value;

                    this.info = value;
                    console.log(value);

                }

            }

        });

    </script>

</body>
</html>
Run Code Online (Sandbox Code Playgroud)

update每次用户键入某个内容时将触发一个方法的输入.这里的想法是更改info使用用户输入中键入的值调用的数据属性的值.

但是,由于某种原因,data属性的值不会改变.console.log(value)每次update触发方法时,当前输入值都会在控制台中正常打印,但不会更改info属性.

那么,如何使这项工作?

html javascript dom vue.js

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

如何防止图像视图被具有可变尺寸的文本视图“推”到屏幕外?

在约束布局中,我有一个 textview,旁边有一个 imageview: 在此处输入图片说明

但有时 textview 中的文本可能很长,有时跨越多行。在这些情况下,图像视图被推到视图之外: 在此处输入图片说明

即使在图像视图和视图容器之间添加约束,图像视图也会被推到视图之外。

目标是始终将图像放在文本旁边,如果它增长,只要不超出视图,图像就会开始被推到一边。当它触及视图的边界时,它应该留在那里,而文本换行到下一行。

这个代码块只是展示了第二张图的情况:

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">

<TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/textView" android:layout_marginTop="8dp"
        app:layout_constraintTop_toTopOf="parent" app:layout_constraintStart_toStartOf="parent"
        android:layout_marginStart="8dp"
        tools:text="This is a cat with a lot more text next to it so pay attention  "/>
<ImageView
        android:layout_width="30dp"
        android:layout_height="30dp" tools:srcCompat="@tools:sample/avatars[3]"
        android:id="@+id/imageView"
        app:layout_constraintStart_toEndOf="@+id/textView" android:layout_marginStart="8dp"
        android:layout_marginTop="8dp" app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintEnd_toEndOf="parent" app:layout_constraintHorizontal_bias="0.0"/>

</androidx.constraintlayout.widget.ConstraintLayout>
Run Code Online (Sandbox Code Playgroud)

我已经尝试过使用障碍和指南,但它们确实不适用于这种情况。textview 需要是 wrap_content 因为它的大小是可变的并且最好使用约束布局,这就是我没有使用另一个的原因。链在这里也不起作用。

android android-constraintlayout

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

如何在 kotlin 中读取 stdin 中的所有行?

我知道可以使用 while 循环使用 readLine 函数从 stdin 获取多行输入。

kotlin 中是否有一个函数可以在不使用 JVM api 的情况下从 stdin 一次检索所有行?

stdin kotlin

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