vue父子组件传参过程:
时间: 2023-07-25 18:08:32 浏览: 88
person = personList.get(position);
AlertDialog.Builder builder = new AlertDialog.Builder(PersonActivity.this);
builder.setTitle("Delete Person").setMessage("在 Vue 中,父组件向子组件传递数据可以通过 props 实现。具体过程如下:
1.Are you sure you want to delete this person?")
.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
@Override
public 在父组件中定义要传递的数据,例如:
```
<template>
<div>
<child-component :message void onClick(DialogInterface dialog, int which) {
SQLiteDatabase db = dbHelper.getWritableDatabase();
db.delete(DBOpenHelper.TABLE_STUDENT, DBOpen="msg"></child-component>
</div>
</template>
<script>
import ChildComponent from './ChildComponent.vue';
export default {
componentsHelper.COLUMN_STUDENT_ID + " = ?",
new String[]{String.valueOf(person.getId())});
personList.remove(person);
person: {
ChildComponent
},
data() {
return {
msg: 'Hello, child component!'
}
}
}
Adapter.notifyDataSetChanged();
}
}).setNegativeButton("No", null).show();
return true;
}
});
}
private</script>
```
2. 在子组件中定义 props,例如:
```
<template>
<div>
<p void loadPersonList() {
SQLiteDatabase db = dbHelper.getReadableDatabase();
Cursor cursor = db.query(DBOpenHelper.TABLE_STUDENT, null>{{ message }}</p>
</div>
</template>
<script>
export default {
props: {
message: String
}
}
, null, null, null, null, null);
while (cursor.moveToNext()) {
int id = cursor.getInt(cursor.getColumnIndex(DBOpenHelper</script>
```
这样,父组件中的 msg 数据就会通过 props 传递给子组件的 message 属性.COLUMN_STUDENT_ID));
String name = cursor.getString(cursor.getColumnIndex(DBOpenHelper.COLUMN_STUDENT_NAME));
String myclass = cursor.getString(cursor.getColumnIndex(DBOpenHelper.COLUMN_STUDENT_CLASS));
Person person = new Person(id, name, myclass);
personList.add(person);
,子组件中就可以使用该属性进行渲染。注意,子组件中的 props 必须要声明类型,否则会收到一个警告。
阅读全文