import QtQuick 2.11
import QtQuick.Controls 2.4
Rectangle
{
    width:640
    height:480
    color:"#cfcfc0"
    anchors.margins: 6
    property bool load1: true
    Button
    {
        id:button
        text:"点击加载Loader"
        anchors.horizontalCenter: parent.horizontalCenter
        onClicked:
        {
            if(parent.load1)
            {
                loader.source = "SubRect1.qml"
                parent.load1 = false
            }
            else
            {
                loader.source = "SubRect2.qml"
                parent.load1 = true
            }
        }
    }
    Loader
    {
        id:loader
        width: parent.width - 12
        height: parent.height - button.height - 12
        anchors.horizontalCenter: parent.horizontalCenter
        anchors.topMargin: 6
        anchors.top: button.bottom
    }
}
SubRect1.qml
import QtQuick 2.11
import QtQuick.Controls 2.4
Rectangle
{
    width:480
    height:320
    color:"#0fefc0"
    Component.onCompleted:
    {
        console.log("SubRect1.qml loaded")
    }
    /*Component.onDestroyed:
    {
        console.log("SubRect1.qml onDestroyed")
    }*/
    Component.onDestruction:
    {
        console.log("SubRect1.qml onDestructed")
    }
}